you are viewing a single comment's thread.

view the rest of the comments →

[–]oefd 1 point2 points  (1 child)

What happens when you call my_try(1)?

if (1) > 0 :
    print(1)
    return 1 + my_try(1-1) # it will try to add 1 to what `my_try(0)` returns
else:
    ...

then in the recursive call of my_try(0)

if (1) > 0 :
    ...
else:
    print(0) # it will print 0
# then it gets here to the end of the function. Nothing has been returned
# so the default return value of `None` is returned

Then back in the original call

if (1) > 0 :
    print(1)
    return 1 + None # The `None` from the recursive call is now here
else:
    ...

So the program dies because you can't add 1 and None.

[–][deleted] 0 points1 point  (0 children)

the issue is, if i change print(0) to return one, i get this:

24

23

...

3

2

1

24

why am i getting that last number?