# L-11 MCS 275 Fri 5 Feb 2010 : enumbits # # enumerates all combinations of n bits def enumbits(k,L): """ writes all bit combinations of len(L), starting at the k-th position """ if k >= len(L): print L else: L[k] = 0 enumbits(k+1,L) L[k] = 1 enumbits(k+1,L) def main(): """ prompts the user for number of bits and initializes the list """ n = input('Give number of bits : ') L = range(0,n) enumbits(0,L) main()