# purpose: construct list of base 2 digits whose length is user- # specified # want random values, need the random module import random # get the number of wanted bits reply = input('How many bits: ') n = int(reply) print() # keep track of the bits seen so far as a list bits =[] # start off with an empty list options = [0, 1] for i in range(0, n): # i is the iterator # indent everything that needs to happen in the loop, generate a number and put it in the list # each iteration want to add another bit to the list of # bits so far # get the next bit bit = random.randrange(0, 2) # random binary digit, will give you either a 0 or a 1 bit = random.choice( options ) # another option, pick something from the options list # append the bit to the list of bits so far bits.append(bit) bits = bits + [bit] # another way to add something to a list, combine two lists # print bits print(bits)