Finding factorial of a number using while True in python

Try out this code below:

print("Enter a negetive number to terminate the program ")
while True:
     factorial=1
     x=int(input("Enter the number "))
if x<0:
    print("Negetive number has no factorial\n Thanks for trying")
    break
elif x==0:
    print(x,"!=",1)
else: 
    for i in range(1,x+1):
        factorial=factorial*i
    print(x,"!=",factorial)

Leave a comment