Question: Use Python to code this problem. Introduction - Somewhere along the line as a kid you played the card game called War. It's a simple
Use Python to code this problem.
Introduction - Somewhere along the line as a kid you played the card game called War. It's a simple two-player game. You divide a deck of cards into two, and each player gets half the cards. Next, each player turns over the top card of their decks. If player 1 has the higher card, they win and take both cards. Both the cards totoals are added to player 1's score. The same happens when player 2 has the higher card.
Program Specifications - Your program will allow a human user to play several rounds of war with the computer. Each round of the game will have the following structure:
The program will ask the user if they want to exit, play, or show the score.
If the user chooses exit by typing "e" or "E", then the game should print a goodbye message.
If the user chooses show score by typing "s" or "S", then the game should display the number of rounds won for each player and the total score of cards won for each player.
If the user chooses play by typing "p" or "P", then the program should choose a card randomly for both the human player and computer player. The program should then print who won, followed by the cards chosen for each player.
If the round results in a tie, the program should print that a tioe occurred (and the specific cards that caused the tie). It should not add the value of the cards to each player's score or increment the number of wons or losses. Instead, it should throw out those cards, and the program should immediately choose another card for each player. This behavior should repeat until a player actually wins. At that point, increment that player's rounds won counter by one and add the total score of the cards for just the tie-break round to the winner's score.
If the user inputs something other than the exit, play, or show letters, the program should detect the invalid entry and ask the user to make another choice.
For this version of the game, you must program the computer to pick cards randomly. To do this you should put the following code at the top of your program:
import random
random.seed()
This is the code necessary to set up a random number generator. Each time you pick a random number you use:
picked=random.ran
This will produce a value from 1 to 13 INCLUSIVE (notice this is different from the way range works.) 1=Ace, 2=2, 3=3, ... 10=10, 11=Jack, 12=Queen, and 13=King.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
