''' Purpose: deepen variable manipulation understanding. Problem: track the number of rabbits over five generations, where the number of rabbits doubles each generation. at the start there are two rabbits ''' # first generation generation = 1 nbr_rabbits = 2 # print( 'Memory box for generation', id( generation ) ) # id() is a function, gives you the location in your computer of the value of variable (generation) # you don't need to know this print( 'Generation: ', generation ) print( 'Rabbits: ', nbr_rabbits ) reply = input( 'Enter when ready: ' ) # waits until user enters something # next generation generation = generation + 1 # generation on the right is the old value of generation --> update the variable generation # new value of generation on the left --> now holds 2 because old generation value is 1 # increment = adding nbr_rabbits = nbr_rabbits * 2 # doubles the # of rabbits from the last generation # here we are updating the two variables we had before # from here on out, generation and nbr_rabbits will have the new values; unless we update them again # = is the assignment operator: we are assigning values on the right to the variables on the left print( 'Generation: ', generation ) print( 'Rabbits: ', nbr_rabbits ) reply = input( 'Enter when ready: ' ) # waits until user enters something # next generation generation = generation + 1 # old (Right) generation = 2 --> 2 + 1 = 3 (new (Left) generation) nbr_rabbits = nbr_rabbits * 2 # old (Right) nbr_rabbits = 4 --> 4 * 2 = 8 (new (Left) nbr_rabbits) # you can update the same variables, it only changes from the point you update onwards # the old value of the variables are gone; you can't get it back # when you are assigning values to a variable, you are storing them to that variable # the ability to update variables can give you the ability to accumulate things # like finding the total of a group of numbers - we'll get to this soon print( 'Generation: ', generation ) print( 'Rabbits: ', nbr_rabbits ) reply = input( 'Enter when ready: ' ) # waits until user enters something # next generation generation = 4 nbr_rabbits = 16 print( 'Generation: ', generation ) print( 'Rabbits: ', nbr_rabbits ) reply = input( 'Enter when ready: ' ) # waits until user enters something # next generation generation = 5 nbr_rabbits = 32 print( 'Generation: ', generation ) print( 'Rabbits: ', nbr_rabbits ) # variables can be re-used and updated # what happens when you have bigger generations? Let the computer to double, instead of doing it manually # identifier vs variable # identifier = name # print() is a name for a function # generation is a name for a variable # syntax rule: has to start with a letter, and can be followed by numbers and other characters; has to be one word # style rule: snake_case # variable = thing that stores a value in memory # our programs so far are static - they run the same thing every time # usually programs want to be interactive - get information from the user and do things with that info # give output depending on the user's input