22.7k views
2 votes
Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the case of a tie, draw more cards. Repeat until someone wins the round. The function has two parameters: the name of player 1 and the name of player 2. It returns a string with format ' wins!'. For instance, if the winning player is named Rocket, return 'Rocket wins!'.

User Anroche
by
4.3k points

1 Answer

6 votes

Answer:

Here you go, Change it however you'd like :)

Step-by-step explanation:

import random as r

def play_round(p1, p2):

cards = [1,2,3,4,5,6,7,8,9,10,"J","Q","K","A"]

play1 = r.choice(cards)

play2 = r.choice(cards)

while play1 == play2:

play1 = r.choice(cards)

play2 = r.choice(cards)

if cards.index(play1) > cards.index(play2):

return f"{p1}'s Card: {play1}\\{p2}'s Card: {play2}\\The Winner is {p1}"

else:

return f"{p1}'s Card: {play1}\\{p2}'s Card: {play2}\\The Winner is {p2}"

print(play_round("Bob","Joe"))

User Marco Martignone
by
4.4k points