1
def bunnies(n,months,quantity):
    print(quantity)
    if n == months:
        return quantity
    else:
        quantity=quantity+quantity
        bunnies(n+1,months,quantity)



months=int(input("How many months ?"))
quantity=1
n=0
bunnies_total=bunnies(n,months,quantity)
print(bunnies_total)

For some reason my function returns None, I can't figure it out.

2
  • 3
    You must return the result of the bunnies call in your else. Commented May 11, 2016 at 10:05
  • 1
    fix your indentation Commented May 11, 2016 at 10:06

1 Answer 1

4

Your else branch doesn't return anything, which means in python it will just return None. Slap a return on the call to bunnies, and you should be OK:

def bunnies(n,months,quantity):
    if n == months:
        return quantity
    else:
        quantity=quantity+quantity
        return bunnies(n+1,months,quantity) # Here
Sign up to request clarification or add additional context in comments.

1 Comment

I have to wait 7 minutes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.