Write a Python Program to Shuffle Deck of Cards

Python Program to Shuffle Deck of Cards

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn  Python programming concepts. You can learn Python language at your own speed and time. One can learn concepts of Python language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Python Program to Shuffle Deck of Cards
Python Program to Shuffle Deck of Cards

Write a Python Program to Shuffle Deck of Cards

PROGRAM: Python Program to Shuffle Deck of Cards

/* Python Program to Shuffle Deck of Cards */

# Python program to shuffle a deck of card

# 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

		

Leave a Reply

Your email address will not be published. Required fields are marked *