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.
    – Baart
    Commented May 11, 2016 at 10:05
  • 1
    fix your indentation
    – kmaork
    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
1
  • I have to wait 7 minutes. Commented May 11, 2016 at 10:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.