Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 10 - Lists - Programming Exercises - Page 354: 10.25

Answer

code

Work Step by Step

# 10.25 (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. import random cards = ["Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"] picks = [] s = 0 while True: for i in range(4): p = random.randint(1, 13) picks.append(p) s = sum(picks) if s == 24: print('The picks are', "(", cards[picks[0] - 1], ",", cards[picks[1] - 1], ",", cards[picks[2] - 1], ",", cards[picks[3] - 1], ")") break picks = []
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.