(Game: pick four cards) Write a program that picks four cards from a deck of 52 cards and computes their sum. An ace, king, queen, and jack represent 1, 13, 12, and 11, respectively. Your program should display the number of picks that yield the sum of 24.
Program Code:
import random
# Create a list representing a deck of 52 cards
deck = list(range(1, 14)) * 4 # Each card is represented by a number from 1 to 13
# Initialize a counter to keep track of the number of picks that yield the sum of 24
count = 0
# Perform 10,000 iterations to pick four cards and compute their sum
for _ in range(10000):
# Shuffle the deck
random.shuffle(deck)
# Pick four cards from the shuffled deck
pickCards = deck[:4]
# Compute the sum of the picked cards
cardSum = sum(pickCards)
# Check if the sum is equal to 24
if cardSum == 24:
count += 1
# Display the number of picks that yield the sum of 24
print("Number of picks that yield the sum of 24:", count)
Executed Output 1:
Number of picks that yield the sum of 24: 463
Executed Output 2:
Number of picks that yield the sum of 24: 452