In this program, we used the product() function in itertools module to create a deck of cards.
Python Program to Shuffle a Deck of Cards
# Python program to shuffle a deck of card # importing modules import itertools, random # make a deck of cards # we used the product() function in itertools module to create a deck of cards deck = list(itertools.product(range(1,14),['Spade','Heart','Diamond','Club'])) # shuffle the cards random.shuffle(deck) # draw five cards print("You got:") for i in range(3): print(deck[i][0], "of", deck[i][1])
Output:
You got:
4 of Spade
12 of Club
2 of Diamond