Question

In: Computer Science

This for a Python Class Suppose that a scientist is doing some important research work that...

This for a Python Class

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 produce 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 Pairs of Breeders Adult Pairs of Non-breeders Pairs of Baby Rabbits Born (same as the # of breeder pairs) Sum of Breeders, Non-breeders, and Babies
1 0 1 0 1

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

Month Adult Pairs of Breeders Adult Pairs of Non-breeders Pairs of Baby Rabbits Born (same as the # of breeder pairs) Sum of Breeders, Non-breeders, and Babies
1 0 1 0 1
2 1 0 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 Pairs of Breeders Adult Pairs of Non-breeders Pairs of Baby Rabbits Born (same as the # of breeder pairs) Sum of Breeders, Non-breeders, and Babies
1 0 1 0 1
2 1 0 1 2
3 1 1 1 3
4 2 1 2 5

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 of adult rabbit pairs (those over 1 month old), which is the sum of adult breeders + adult non-breeders.
    • The number of baby rabbits pairs produced this month (same as the number of adult breeders this month).
    • The total number of rabbit pairs in the lab, which the sum of adult rabbits and baby rabbits
  3. Calculate how many months it will take until the number of rabbits exceeds the number of available cages (500).
  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

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

# Table of rabbit pairs
Month, Adults, Babies, Total
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

Solutions

Expert Solution

SOLUTION-
I have solve the problem in python code with comments and screenshot for easy understanding :)

CODE-

#python code
#main
def main():
# set the initial month and declaration
month = 1
old_adults = 0
old_babies = 0
adults = 1 # initial adult pair
babies = 0 # initial babies pair
total = 0 # storing the total number of rabbit pairs
max = 500 # maximum number of rabbit pairs that can be accomodated
# output file
file = open("rabbit_sim.txt",'w')
# header of output file
file.write("# Table of rabbit pairs\n")
file.write("Month, Adults, Babies, Total\n")
# calculate the total number of rabbit pairs for the month
total = adults+babies
# loop that continues till total rabbit pairs < max
while total < max:
# output the counts to file
file.write(str(month)+", "+str(adults)+", "+str(babies)+", "+str(total)+"\n")
month += 1 # increment the month
# set the old_adults and old_babies to current adults and babies
old_adults = adults
old_babies = babies
# calculate the adults and babies for next month
babies = adults
adults = old_adults + old_babies
total = adults+babies # calculate the total number of rabbit pairs for the month
  
# output the counts when the total rabbit pairs > 500
file.write(str(month)+", "+str(adults)+", "+str(babies)+", "+str(total)+"\n")
# output the month number when it runs out of cages
file.write("# Cages will run out in month "+str(month))
# close the file
file.close()

#call the main function
main()


SCREENSHOT-


IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

research and  find an important mathematician or scientist whose work is especially interesting or important.? Explain briefly...
research and  find an important mathematician or scientist whose work is especially interesting or important.? Explain briefly why their discoveries are important for us today? Can you find any particular analytical trait that would be advantageous for us to have?
public class Question4 { /* For this exercise you will be doing some basic operations to...
public class Question4 { /* For this exercise you will be doing some basic operations to write to a file. You will be creating your very own Secrets of the Universe (TM)    You can use the PrintWriter class to write to files (Chapter 11.4)    Your code should perform the following actions:    1) Open/Create a file for writing at the following location: "files/question4/MySecretsOfTheUniverse.txt" * If the file already exists you will want to overwrite its contents. 2) Add...
A student is doing some research on the importance of agents used in the laboratory room...
A student is doing some research on the importance of agents used in the laboratory room to kill certain prokaryotes and eukaryotes. Can you list the six different agents and what each specializes for?
For any controlled scientific study, a scientist starts with an observation, does some research to develop...
For any controlled scientific study, a scientist starts with an observation, does some research to develop a hypothesis, and then designs an experiment that compares some baseline group with a test group. Data are then collected to confirm or refute the hypothesis. As you review the following study, consider whether the researchers correctly followed the scientific method. In the late 1990s, gastroenterologist Andrew Wakefield, along with a research team, set out to determine whether bowel disease caused by vaccines led to...
The ethics involved in using human embryos for cloning research are complicated. Some scientist claim a...
The ethics involved in using human embryos for cloning research are complicated. Some scientist claim a moral obligation to pursue such research, with the goal of creating compatible tissue for transplants, or discovering genetic information that might cure incurable diseases. Others think it is wrong.What is your opinion?
Organizational culture is important to a business. Research a company and share with the class the...
Organizational culture is important to a business. Research a company and share with the class the organizational culture of the company. Is the culture working? If you were on the management team, what changes would you make to the current culture?
One of your audit clients approaches you about doing some additional work for the company. Some...
One of your audit clients approaches you about doing some additional work for the company. Some of the things that the client needs your firm’s help with include: Financial projections that includes the acquisition of a failing company. Preparation of forecasted financial statements for a bank loan. You are excited to be able to present this new opportunity to the partners of the firm, but there are several factors the firm must consider. Assume your firm decides to provide these...
Marie Curie was a famous French-Polish scientist known for her pioneering research on radioactivity. Her work...
Marie Curie was a famous French-Polish scientist known for her pioneering research on radioactivity. Her work not only brought her fame but her death as well; she developed aplastic anemia due to radiation exposure. She experienced recurrent and prolonged infections (viral, bacterial, parasitic, and fungal). Explain why she suffered from recurrent infections. Be sure to mention the different types of WBC and the relation to the various infections, and the reasons why she lacked the cell-mediated and the humoral response....
Marie Curie was a famous French-Polish scientist known for her pioneering research on radioactivity. Her work...
Marie Curie was a famous French-Polish scientist known for her pioneering research on radioactivity. Her work not only brought her fame but her death as well; she developed aplastic anemia due to radiation exposure. She experienced recurrent and prolonged infections (viral, bacterial, parasitic, and fungal). Explain why she suffered from recurrent infections. Be sure to mention the different types of WBC and the relation to the various infections, and the reasons why she lacked the cell-mediated and the humeral response.
Suppose you meet an extraterrestrial alien. The alien is doing a research project on the health...
Suppose you meet an extraterrestrial alien. The alien is doing a research project on the health care system in the United States since the 1960’s. The alien understands that disease exists and that resources are scarce. Explain to the alien the foundational parts of our health care system AND how our health care system has evolved since the 1960’s and why.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT