68.2k views
21 votes
Write a program that simulates picking a card from a deck of 52 cards. Your program should display the rank (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King) and suit (Clubs, Diamonds, Hearts, Spades) of the card using python

User Dave Smits
by
6.0k points

1 Answer

4 votes

Answer:

Step-by-step explanation:

The following is a python function that has arrays with all the cards available and then uses random to choose a random card from the dictionary. Finally it prints out the card chosen...

import random

def choose_card():

card = ["Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King']

symbols = ['Clubs', 'Diamonds', 'Hearts', 'Spades']

chosen_card = str(card[random.randint(0, len(card))])

symbols = symbols[random.randint(0, len(symbols))]

print("Chosen Card: " + chosen_card + " of " + symbols)

User Lidy
by
6.7k points