I'm trying to write a Fibonacci sequence that can take a user's input as the multiplier for the generational increase in rabbits, i.e., 4 pairs of offspring produced for each pair of mature rabbits.
I have tried storing the integer form of the input in a new variable and moving around the position of when the raw input is asked:
def fibonacci(x):
if x == 1:
rabbit_pairs = 1
return rabbit_pairs
elif x == 2:
rabbit_pairs = 1
return rabbit_pairs
elif x > 2:
y = int(input("How many offspring per pair? "))
rabbit_pairs = fibonacci(x-1) + (y * fibonacci(x-2))
return rabbit_pairs
When I run my code, if x > 2, my input question is asked but it keeps getting asked instead of returning the corresponding number of rabbits. If x == 5, the command prompts for the number of rabbits per pair and then keeps asking for the number of rabbits per pair.