197k views
4 votes
Take the program written last weekend that creates a deck of cards, shuffles them, and then lists them out. Modify the program to 'deal' two hands of cards (two players). Each player will be dealt 5 cards. Deal one to the first player, then one to second player. Repeat until both players have 5 cards in their hand. Then compute the total points in each player's hand and determine the winner with the most points. If a player has an ace, then count that as 11 points. Print out the winning player total points and then his cards. Then print out the losing player total points and his cards. Turn in both your code and a copy of the screen output.

User RobG
by
4.4k points

1 Answer

1 vote

Answer: Here, you might need to make some changes to format it how you'd like, but it gives you the desired output :)

Step-by-step explanation:

import random as chunky

def play():

hand1, hand2 = [], []

for n in range(5):

hand1.append(chunky.choice(cardList))

hand2.append(chunky.choice(cardList))

print("Hand 1: ", end= "")

for n in hand1:

print(n, end= " ")

print()

print("\\Hand 2: ", end= "")

for n in hand2:

print(n, end= " ")

print()

while "A" in hand1:

hand1[hand1.index("A")] = 11

while "A" in hand2:

hand2[hand2.index("A")] = 11

print(f"\\Hand 1 Total: {sum(hand1)} Hand 2 Total: {sum(hand2)}")

print("\\Hand 1 WINS!") if sum(hand1) > sum(hand2) else print("\\Hand 2 WINS!")

cardList = [1,2,3,4,5,6,7,8,9,10,"A"] #Skipped King, Queen, and Jack. Did not know how to incorperate them

chunky.shuffle(cardList)

looper = True

while looper == True:

play()

x = input("\\\\Would you like to go again?(y/n): ")

if x.lower() == "n":

quit()

User PinkTurtle
by
4.5k points