Solution Exercise 42

Write a list comprehension that uses nested for-clauses to create a single list with all 36 different dice combinations from (1,1) to (6,6).

Hint:
The nested for-clauses mean that you have to independent for-loops, one for each dice. Also note that each combintaion can be stored as a tuple.

def main():
    two_dice_comb = [(d1, d2) for d1 in range(1,7) for d2 in range(1,7)]
    
    #This variable is to control printing in columns
    col = 0
    for comb in range(36):
        #Print the combination, a space and don't change line
        print(two_dice_comb[comb]," ", end="")
        col += 1
        if col == 6:
            col = 0
            print() #New line

if __name__ == '__main__':
    main()