0

I think there is something wrong with this code, I don’t know what it is though

def fun(x): if x % 2 == 0: return 1 else: return print(fun(fun(2)) + 1)

27th Sep 2021, 11:26 PM
Jenkins
4 RĂ©ponses
+ 2
Jenkins Were you trying to do this? def fun(x): return x%2 ==0 print(fun(fun(2))+1)
28th Sep 2021, 2:06 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 4
The problem is that if number is odd, your function returns nothing (None type) which is a problem, as later you are trying to add "None" to 1, which python obviously can't do.
27th Sep 2021, 11:36 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
Maybe you wanted print(fun(fun(2)+1)) #1
28th Sep 2021, 12:56 AM
Solo
Solo - avatar
0
Rik Wittkopp 👍😉
28th Sep 2021, 2:14 AM
Solo
Solo - avatar