Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

Help debugging code written in python to get the output from the attached image, 

 

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()

if __name__ == '__main__':
main() #excucte main function

 

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()
if
' main_':
name
main() #excucte main function
expand button
Transcribed Image Text: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() if ' main_': name main() #excucte main function
# 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
expand button
Transcribed Image Text:# 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
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY