Write Python code to determine the factors of a positive number N entered by the user. The program must store the number of factors of N as an array. Code must use the numpy.size() function to count the elements. Example:

If N=7, the factors are: [1, 7] and the number of factors is 2. The output is "The number of 7 factors is 2".
If N=9, the factors are: [1, 3, 9] and the number of factors is 3. The output is: "The number of factors 9 is 3".
Hint: you can use the module operator % to determine if the number N is divisible by a factor i , where i is a variable: 1, 2, ..., N, and count the factors.

1 answer

import numpy as np

N = int(input("Enter a positive number: "))
factors = []

for i in range(1, N+1):
if N % i == 0:
factors.append(i)

num_factors = np.size(factors)
print("The number of factors", N, "is", num_factors)