+ 1

Why does this recursion code (python) give an error

def factorial(x): if(x==1): return x else: return x * factorial(x-1) n=input("enter a positive number") print(factorial(n))

24th Sep 2017, 1:39 PM
Sushant Kulkarni
Sushant Kulkarni - avatar
3 Respostas
+ 2
n=input(".......") here what ever u give input thats a string... u need to convert n to integer... do this... n=int(input("...."))
24th Sep 2017, 3:24 PM
sayan chandra
sayan chandra - avatar
+ 2
I figured the answer out: change n=input("....") to n=int(input("..."))
24th Sep 2017, 3:26 PM
Sushant Kulkarni
Sushant Kulkarni - avatar
- 1
yep... thats it... ✌✌
24th Sep 2017, 3:32 PM
sayan chandra
sayan chandra - avatar