I'm trying to learn Python, but it's not going well. I wrote this, but it doesn't work. I've found examples that do work, but when I compare them I don't get what I'm doing different.
def fact(x):
x = int(input("enter number: "))
if x == 0:
return 1
return x * fact(x - 1)
print(fact(x))
I want it to ask for the user's input and then find the factorial of it. What am I doing wrong?
factis supposed to take an argument, 'x'. You callfact(x)butxis not defined. Also, you probably don't want to take input and redefinexinside of thefactfunction.