""" Purpose: simple simulation of rabbit growth over four generations """ # Get simulation info reply1 = input( "How many rabbits: " ) # take whatever number is typed reply2 = input( "Growth rate per generation: " ) # hands back a string of that value starting_number_of_rabbits = int( reply1 ) # int() only works with ONE input generation_growth_rate = int( reply2 ) # this is a GOTCHA # we could say reply1 = int( reply1 ) and that would work too # we'll be switching from strings and integers all the time so make sure # this makes sense now # t1 = type(starting_number_of_rabbits) # print(starting_number_of_rabbits, t1) # python knows what kind of data is in each variable # if you want to do math with a string, you have to change it to a number # using int() or float() # starting_number_of_rabbits will not change # generation_growth_rate is also constant # the int() function takes whatever ONE input is given to it and converts it # to an integer number as best it can # int( "five" ) will not return 5, int( '5' ) will return 5 # float( '5.6' ) = 5.6 # an integer string looks like this '6' # the int() function allows you to change data types from strings to numbers # remember our arithmetic functions will only work with numbers # don't call functions inside functions, stay simple :) # we_use_snake_case_in_python # its_long_and_short_like_snake # First generation number_of_rabbits = starting_number_of_rabbits # track current number of rabbits generation = 1 # track generation # ellipsis (...) is a placeholder that python is chill with # ... means i'll put something here later print() # blank line print( "Generation:", generation ) print( "Rabbits: ", number_of_rabbits ) # Next generation (second) number_of_rabbits = generation_growth_rate * number_of_rabbits # each rabbit produces that many new rabbits # we are updating the value of the variable # python does not care if a variable is on both sides of an assignment statement # i'm going to compute the right side and store it in the left # computation of right side is independent of target (left side) # erase the connotation of = and equals when you enter CS generation = generation + 1 # remember this is assignment - take the current value and add 1 print() print( "Generation:", generation ) print( "Rabbits: ", number_of_rabbits ) # Next generation (third) number_of_rabbits = generation_growth_rate * number_of_rabbits generation = generation + 1 print() print( "Generation:", generation ) print( "Rabbits: ", number_of_rabbits ) # Next generation (fourth) number_of_rabbits = generation_growth_rate * number_of_rabbits generation = generation + 1 print() print( "Generation:", generation ) print( "Rabbits: ", number_of_rabbits ) # could this be simplified? yes. we will do that later! for loop # loops let you repeat actions # gotta keep y'all invested # PLEASE DO NOT BRING COVID HERE # watch the videos, attend office hours, we'll help you # run all the test cases given, as different test cases test different aspects # pay attention - read the problem fully and run all the test cases # tips to avoid confusing your code # use descriptive variable names! # walk through your code without running it, check that each variable is correct