+ 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

2nd Jan 2021, 6:08 PM
‎ Герман Папанов(הרמן פפנוב)‎
‎ Герман Папанов(הרמן פפנוב)‎ - avatar
8 Réponses
+ 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);"
2nd Jan 2021, 6:57 PM
rodwynnejones
rodwynnejones - avatar
+ 2
Посмотрите
2nd Jan 2021, 6:34 PM
‎ Герман Папанов(הרמן פפנוב)‎
‎ Герман Папанов(הרמן פפנוב)‎ - avatar
+ 1
You have to call the function outside its definition then there are an error in the base condition if x == 1: return ....
2nd Jan 2021, 6:28 PM
HBhZ_C
HBhZ_C - avatar
+ 1
So what do I have to do?
2nd Jan 2021, 6:29 PM
‎ Герман Папанов(הרמן פפנוב)‎
‎ Герман Папанов(הרמן פפנוב)‎ - avatar
+ 1
I've changed
2nd Jan 2021, 6:34 PM
‎ Герман Папанов(הרמן פפנוב)‎
‎ Герман Папанов(הרמן פפנוב)‎ - avatar
+ 1
Still
2nd Jan 2021, 6:35 PM
‎ Герман Папанов(הרמן פפנוב)‎
‎ Герман Папанов(הרמן פפנוב)‎ - avatar
0
Why you type return 1 in base condition not return x?
2nd Jan 2021, 6:31 PM
HBhZ_C
HBhZ_C - avatar
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
2nd Jan 2021, 6:32 PM
Stefanoo
Stefanoo - avatar