The design may look like this:
while True: N = input("Please input factorial you would like to calculate: ") try: # try to ... N = int(N) # convert it to an integer. except ValueError: # If that didn't succeed... print("Invalid input: not an integer.") continue # retry by restarting the while loop. if N > 0: # valid input break # then leave the while loop. # If we are here, we are about to re-enter the while loop. print("Invalid input: not positive.")
In Python 3, input() returns a string. You must convert it to a number in all cases. Thus, your N != int(N) does not make sense, since you cannot compare a string with an int.
Instead, try converting it to int directly, and if that doesn't work, let the user log in again. This rejects the floating point numbers, as well as everything else, which is not valid as an integer.
source share