''' Purpose: construct list of n base 2 digits for a user-supplied n ''' import random # want random values, then we need the random module # get the number of wanted bits reply = input( 'How many bits: ' ) n = int( reply ) print() # create an empty list of bits bits = [] # start off with an empty list # add n random 0/1's to bits # If we have examples where we're looping through sequences, strings, # summing numbers up, etc., we can see we use the loop variable in the loop # but it kindaaaa depends on the problem when we use the loop variable value # it matters if we're using the loop variable values (the smaller # parts of the sequence) or not so there's no definitive time we do vs. # don't use a loop variable in a for loop body.. for i in range( 0, n ) : # i is the iterator # 0 to n and 1 to n + 1 # In this example, is the same # of times # i is just used to say "I want to do this this many times - this many # iterations" i=0 i=1 i=2 THREE TIMES (I'm just doing it this many times) # each iteration want to add another bit to the list of bits # get the next bit bit = random.randrange(0,2) # randrange(2) also works! [0,2) -> 0,1s # append the bit to the list of bits so far bits.append( bit ) # .append() is the function to add something into a list # if you have a list you cant do list_name + ... # to add something into a list just do # list_name.append(whatiwannaputinit) # print bits print( bits )