1

I am making a program in python which accepts a positive integer from the user and tells if the integer entered is a 'perfect factorial' or not.

import numpy as np

n = int(input('Enter positive integer: '))
i = 1

while n != 1:

    if np.mod(n, i) == 0:
        n = n/i
        print(n)
        i += 1

    else:
        print("The integer you entered wasn't a perfect factorial")
        break

Could you suggest me a method to get n as such that if the user enters an invalid input (like strings, floats or negative integers), the program keeps asking for another input? Also, if you could tell me how to convert the program into def() form would be helpful.

sato
  • 125
  • 7

0 Answers0