A working solution but slightly different to support negative numbers, 0 and 1 or greater:
num = int(input("Enter a number: "))
factorial = 1
if num < 0: print("Negative number don't have a factorial")elif num == 0: print("The factorial of 0 is 1")else: for i in range(1,num + 1): factorial = factorial*i print("The factorial of",num,"is",factorial)
I don't do python really, but it looks like this code is incorrect.
I think there are few errors in your code.
You just need to understand and correct few errors in your code.
num=int(input("Enter a number:"))fact=1if(num==0): fact=1else: for i in range(1,num+1): fact=fact*iprint("Factorial of",num,"is",fact)
1.Before if statement, you have to declare a fact.