+ 2
How do you get a value and then it's wrapped up and done through this code?
I need to enter the number. 5 https://code.sololearn.com/c7qWqeXz6a8W/?ref=app
8 odpowiedzi
+ 2
def factorial(x):
if x == 0:
return 1
else:
return x*factorial(x-1)
print(factorial(5))
and/or you can reduce by one iteration by doing "if x == 1 return x (or return 1);"
+ 2
Посмотрите
+ 1
You have to call the function outside its definition then there are an error in the base condition if x == 1: return ....
+ 1
So what do I have to do?
+ 1
I've changed
+ 1
Still
0
Why you type return 1 in base condition not return x?
0
If you want get the user input just use the input function like here.
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/4434/?ref=app