00 T-Mobile 1:20 AM elearn.uta.edu E 2305 War Games! The card game War consists
ID: 3870159 • Letter: 0
Question
00 T-Mobile 1:20 AM elearn.uta.edu E 2305 War Games! The card game War consists of two players who each have a deck of cards. For each hand, each player turns over the top card in his or her deck. The higher card wins that round of play and the winner takes both cards. The game continues until one person has all the cards Create a program that simulates a modified game of War. The computer will play both hands, as PlayerOne and PlayerTwo. For each round the program will generate two random numbers and compare them If the first number is higher, PlayerOne's score is increased by 1 and if the second is higher, PlayerTwo's score is increased by 1. If there is a tie, no score is incremented. When one player reaches a score of 10, that player is deemed the winner and the game ends. The range of numbers should be 1-13 to simulate the values of cards in a deck Display on a worksheet the hand number, PlayerOne's card, PlayerTwo's card, PlayerOne's score, and PlayerTwo's score for the entire game 1 Hand Card Card 2 Player 1 Scoe Player 2 Scoe Due via Blackboard on Tuesday, 9/26, at 12:20. This is an individual, not a group assignment.Explanation / Answer
# Dear Student it is a code written in Python3. If you store the output as a csv file you would get the same excel file as shown above.
import random
scorePlayer1 = 0
scorePlayer2 = 0
playRound=0
print("Round, Card-1, Card-2, Player-1 Score, Player-2 Score")
while (True):
playRound = playRound+1
cardPlayer1 = random.randrange(1, 13)
cardPlayer2 = random.randrange(1, 13)
if(cardPlayer1 < cardPlayer2):
scorePlayer2 = scorePlayer2 +1;
print(playRound,",",cardPlayer1,",",cardPlayer2,",", scorePlayer1,",",scorePlayer2)
if(scorePlayer2 >= 10):
print("Player-2 Wins!")
break;
if(cardPlayer2 < cardPlayer1):
scorePlayer1 = scorePlayer1 +1;
print(playRound,",",cardPlayer1,",",cardPlayer2,",", scorePlayer1,",",scorePlayer2)
if(scorePlayer1 >= 10):
print("Player-1 Wins!")
break;
if(cardPlayer1 == cardPlayer2):
print(playRound,",",cardPlayer1,",",cardPlayer2,",", scorePlayer1,",",scorePlayer2)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.