In: Computer Science
Challenges Using Python 3. Write a program that displays the name of a card randomly chosen from a complete deck of 52 playing cards. Each card consists of a rank (Ace. 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King) and a suit (Clubs, Diamonds, Hearts. Spades).
#Here we will use libraries such as random & itertools
import itertools #Import itertools library to iterate over lists
import random #Import random library for randomize operations
# Define the list of ranks to be allocated
rank = ['Ace','2','3','4','5','6','7','8','9','10','Jack','Queen','King']
# Define a list of suit to be allocated
suit = ['Clubs','Diamonds','Hearts','Spades']
# Prepare a complete deck comprising of 52 pairs
complete_deck = list(itertools.product(rank,suit))
# Choosing a random card number
num = random.randint(1,52)
# print the card
print('Your card is %s of %s' % (str(complete_deck[num][0]), str(complete_deck[num][1])))