''' Purpose: construct list of n base 2 digits for a user-supplied n ''' import random # want random values, then we need the random module # this is greyed out because we haven't used it yet. once we use a function from random, this will look normal # 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 for i in range( 0, n ) : # i is the iterator # each iteration want to add another bit to the list of bits # get the next bit bit = random.randrange( 2 ) # give me either a 0 or a 1 # other ways: # bit = random.randrange( 0, 2 ) # bit = random.choice( [ 0, 1 ] ) # bit = random.choice( "01" ) <- for this one, we'd have to cast the bit to an int # append the bit to the list of bits so far bits.append( bit ) # add the newly generated random bit to the list # print bits print( bits )