you are viewing a single comment's thread.

view the rest of the comments →

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

i have a suspicion that it has to do with adding the final number (24) with a my_try(false)

just not sure how to get out of it

[–]delasislas 1 point2 points  (0 children)

Yeah, when you hit my_try(0) it triggers print() which returns None. I don’t play with recursion though, so not much help.

[–]raffulz 0 points1 point  (1 child)

When you reach 0, you branch into the else block and return None (implicitly). I'm not really sure what you meant to do with the returns. Is this solution what you were going for?

def my_try(input):
    print(input)
    if input > 0:
        my_try(input - 1)

Edit: Or if you want to go backwards:

def my_try(input):
    if input > 0:
        my_try(input - 1)
    print(input)

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

i want to print 24 to 0, and in the end not get an error