+ 1
I expected 'return x' to be 1 but None was returned. Why??
def fuc(x): if x==1: return x else: x-=1 fuc(x) x=2 print(fuc(x),x)
2 Réponses
+ 5
On line 6, you just call fuc(x), you need to return the result as well by doing return fuc(x).
+ 3
Good question and your expectation is acceptable.
Recursion needs a return. And it is a bit complicated to explain why.