Using the fibonacci sequence for the multiplaction of rabbits

  fibonacci, python-3.x, sequence

I’ve seen a few people ask about this project but I’ve mostly seen psuedocode from people. The idea is that you start out with 1 pair of adult rabbits. It wants me to print a table that contains the months, the number of adult rabbit pairs(those over 1 month old), the number of baby rabbit pairs, the total number of pairs, and what month there will be more rabbit pairs then cages. There are 500 cages and each cage can hold 1 pair of rabbits by month 14 you will run out of cages with a total number of 610 pairs. If anyone can explain to me how to create a table in python that would be fantastic ive figured out the Fibonacci part. Here is the code I’ve gotten so far but this only accounts for the adults and months. How do I add the babies and the total on the same line. Here is also the output.

—INPUT—

print("|month|", "|adult|", "|baby|", "|total|")

def rabbits(n):
if n == 1:
return 1
elif n == 2:
return 1
elif n > 2:
return rabbits(n-1) + rabbits(n-2)

for n in range(1, 15):
print(n, " ", rabbits(n))

—OUTPUT—

1 : 1

2 : 2

3 : 2

4 : 3

4 : 5

6 : 8

7 : 13

8 : 21

9 : 34

10 : 55

11 : 89

12 : 144

13 : 233

14 : 377

Source: Python-3x Questions

LEAVE A COMMENT