Question

# I need the actual code for this... I found a similar response but it was not...

I need the actual code for this... I found a similar response but it was not thorough enough.

Problem

Prerequisites: None

Suppose that a scientist is doing some important research work that requires her to use rabbits in her experiments. She starts out with one adult male rabbit and one adult female rabbit. At the end of each month, a pair of adult rabbits produces one pair of offspring, a male and a female. These new offspring will take one month to mature and become adults.

To illustrate this, consider the first two months. At the beginning of month one, the scientist just has the original one pair of adult rabbits. A table for month one will look something like:

 Month Adult Babies Total 1 1 0 1

At the end of month one this pair of adults produces one pair of offspring. Thus, at the beginning of month two the table will look like this:

 Month Adult Babies Total 1 1 0 1 2 1 1 2

At the end of month two the adults have another pair of baby rabbits. The first pair of babies, born at the end of last month are not old enough to have babies yet, but we will categorize them as adults. So, at the beginning of month three the table looks like this:

 Month Adult Babies Total 1 1 0 1 2 1 1 2 3 2 1 3

The scientist has 500 cages in which to hold her rabbits. Each cage holds one pair of rabbits. Assuming that no rabbits ever die, when will she run out of cages?

Your program must do the following:

1. Open a text file rabbits.csv for writing.  Where it says "print" below, it means "write to the output file". Remember to close the file when done.
2. Print a table that contains the following information for each month.
• The number of months that have passed.
• The number adult rabbit pairs (those over 1 month old).
• The number of baby rabbits pairs produced this month.
• The total number of rabbit pairs in the lab.
3. Calculate how many months it will take until the number of rabbits exceeds the number of available cages.
4. Stop printing when you run out of cages.
5. Print a message giving how many months it will take to run out of cages

Output file should look like the following. Comments in the file begin with '#', and must appear as shown too:

```# Table of rabbit pairs
1, 1, 0, 1
2, 1, 1, 2
3, 2, 1, 3
4, 3, 2, 5
5, 5, 3, 8
6, 8, 5, 13
7, 13, 8, 21
8, 21, 13, 34
9, 34, 21, 55
10, 55, 34, 89
11, 89, 55, 144
12, 144, 89, 233
13, 233, 144, 377
14, 377, 233, 610
# Cages will run out in month 14```

Submission

1. Submit a source code file named main.py.
2. Your code should produce the output file rabbits.csv when run.
You don't need to submit this file because we will run your code.
3. Check the syllabus for other requirements.

Late submissions earn 50 points and no feedback.

0-20 points: design doc is correct and complete
21-100 points: all automated and manual test cases pass

Test Cases

This project has a rubric that matches these test cases, and is used for grading.
Your instructor may also use automated unit test code and/or pylint for grading.

1. easy to find and change initial conditions and stopping values in code
2. program produces file rabbits.csv when run
3. correct comments exist in output file
4. file contains correct data and in CSV format
5. Code has a main function with conditional execution.
6. File has a module docstring with required information in it.
7. Code follows PEP8 Python Style guide for code style (not your book's Java style)
8. Thonny's Assistant or pylint says your code is OK, no warnings.

import csv
def rabbit(n): #performing the calculation
if n==0: #if month is 0 no adult no kids
return 0
#if month is 1 then 1 adult no kids
elif n==1:
return 1
#if month is 2 then 1 adult 1 kids
elif n==2:
return 1
else:
return rabbit(n-1)+rabbit(n-2)
a=[] #list to store one iteration result
month=1 #month variable
kids=0 #kid variable
sum1=1 #total variable
while(sum1<500):#iterate until sum is less than 500

sum1=rabbit(month-1)+rabbit(month) #performing the calculations
#print(sum1)
month=month+1; #increment the month
a = [b[n:n+4] for n in range(0, len(b), 4)]#crating list of list with 4 values at a particular row
new_line="# Cages will run out in month "+str(month-1)
myFile = open('csvexample3.csv', 'w')#reading the file to write data into file
with myFile:
writer = csv.writer(myFile)
writer.writerows(a)
with open('csvexample3.csv', 'a') as a_file: #reading the file to append the last line
a_file.write(new_line)
for i in a:
print(i)