Write a function to find the factors of an input number. The function should have one input n and a single output of a vector whose entries are the factors of n. The only built in functions you are allowed to use are mod or rem (I would prefer mod). Demonstrate that your function works as expected.

Respuesta :

The following is the program.                                                          

Explanation:

  • We should  find the factors of input number
  • We can use  python to find the factors of input number
  • In this program, we can use the mod function.

def print_factors(y):

   print("The factors of",y,"are:")

     for j in range(1, y + 1):

          if y % j == 0:

                print(j)

num = 320

print_factors(num)

The above program calculates the factors of n. Here def is called as define function. We are calculating the factors of y. After that, we are giving them for the condition. If the condition is true it will print the factors of y.