Shuffle Deck of Cards Python
PROGRAM TO SHUFFLE A DECK OF CARDS
# importing modules
import itertools, random
# make 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(5):
print(deck[i][0], "of", deck[i][1])
OUTPUT
You got: 5 of Heart 1 of Heart 8 of Spade 12 of Spade 4 of Spade
Note: Run the program again to shuffle the cards.
Comments
Post a Comment