I'm supposed to be writing a function that find the amount of shoes a given number of dogs would need. It can easily be done with multiplication, but we're required to use recursion, so i have
def dogShoes(n):
total = 0
if n>0:
shoes = n + dogShoes(n)
total = total + 1
if total == 4:
return shoes
But I now realize that line 4 will go towards infinity and the bottom part that I though would stop it won't even be implemented. Is there a way to say when total
is 4
, stop and return the answer without shoes
going towards infinity?