The Student Room Group

Recursion - computer science question?

How would I rewrite this to make a recursive function?

def countdown_itt(n):
while n >= 0:
print (n)
n = n-1
countdown_itt(10)
Reply 1
Original post by ninja24
How would I rewrite this to make a recursive function?

def countdown_itt(n):
while n >= 0:
print (n)
n = n-1
countdown_itt(10)


Have the function call itself. That's what recursive functions do.
You'll need to get rid of the whole loop and have a terminating condition.

You must have an example in your notes?
Original post by mqb2766
Have the function call itself. That's what recursive functions do.
You'll need to get rid of the whole loop and have a terminating condition.

You must have an example in your notes?

I did it, it's fine. Thanks for the reply though.

Quick Reply

Latest