''' Purpose: introduce variable manipulation through assignment ''' print( ) # first generation there are 2 rabbits. each successive # generation doubles the number of rabbits nbr_rabbits = 12 # the value of 2 has been assigned to the label/identifier nbr_rabbits generation = 1 # these identifiers are being assigned to literal values right now print( 'Generation: ', generation ) # 1 print( 'rabbits: ', nbr_rabbits ) # 2 print( ) # next generation nbr_rabbits = nbr_rabbits * 2 # you can update the values of variables generation = generation + 1 # check the previous value of generation and then add one to it # and set that new value to be represented by the identifier "generation" # once something's been updated, # the original value is lost print( 'Generation: ', generation ) # 2 print( 'rabbits: ', nbr_rabbits ) # 4 print( ) # next generation nbr_rabbits *= 2 # same as nbr_rabbits = nbr_rabbits * 2 generation += 1 # same as generation = generation + 1 # nbr_rabbits = ... # ... is a placeholder for code # generation = ... # next generation print( 'Generation: ', generation ) print( 'rabbits: ', nbr_rabbits ) print( ) nbr_rabbits = nbr_rabbits * 2 generation = generation + 1 # next generation print( 'Generation: ', generation ) print( 'rabbits: ', nbr_rabbits ) print( ) # typical updating # start_value = something # start_value = start_value + ____ OR start_value * ______ # the = in Python is the assignment operator # identifier = value sets identifier to be a label representing value # (technically identifier "points to" value in memory, but more on this in later CS classes) # how do I make this go on for a long while? # use a for loop! MORE ON THIS LATER!!!!!!! Don't worry too much about it now. # looping means you can repeat an action... # MORE ON THIS LATER, but the takeaway for now is that loops help us repeat actions # nbr_rabbits = 2 # generation = 1 # n = 100 # for i in range(0, n): # nbr_rabbits = nbr_rabbits * 2 # generation = generation + 1 # print("Generation:", generation) # print("Number of rabbits:", nbr_rabbits) # how to only run certain pieces of code? - if statements help us make decisions of which code to run...more on this later!