I need some help with this program I am trying to finish. This thing is kind of a mess. its the end of a 12 hour day and it's due tonight and I think I'm just making things worse at this point. I'm struggling with implementing input of "4" for the player_choice and getting the program to just say 'Exiting the program' and stop. When I input a choice currently, I get what I think is an endless loop because the entire IDE locks up and crashes.
program requirements:
1) Get and return the value of the computer’s choice as an integer.
2) Use a menu to get, validate, and return the player’s choices.
The player will enter their menu choice for rock, paper, scissors, or quit.
Validate the choice before returning it.
3) Determine the winner. There are a total of 9 possible combinations of
computer and player choices. The menu should always be displayed after the outcome has
been displayed regardless of the outcome
(i.e. ties should be treated the same as any other outcome).
4) After the player chooses to stop playing, display the total number of
games that ended in a tie, the total number the computer won, and the total
number the player won.
Here is the program code:
import random
def main():
display_menu()
print('There were', number_of_tied_games, 'tie games played.')
print('The computer won', number_of_computer_games, 'game(s).')
print('You won', number_of_player_games, 'game(s).')
def process_computer_choice():
choice1 = random.randint(1,3)
return choice1
def process_player_choice():
print('What is your choice?')
choice2 = (input())
while choice2 != "1" and choice2 != "2" and choice2 != "3" and choice2 != "4":
print("ERROR: the choice can only be 1, 2, 3, or 4.")
choice2 = (input("Please enter a correct choice: "))
return choice2
def determine_winner(player_choice, computer_choice, choice2):
while choice2 != "4":
if computer_choice == 1:
if player_choice == "2":
print('Paper covers rock. You win!')
winner = 'player'
elif player_choice == "3":
print("Rock crushes scissors. The computer wins!")
winner = 'computer'
else:
print('The game is tied. Try again.')
winner = 'tied'
if computer_choice == 2:
if player_choice == "1":
print('Paper covers rock. The computer wins!')
winner = 'computer'
elif player_choice == "3":
print("Scissors cuts paper. You win!")
winner = 'player'
else:
print('The game is tied. Try again.')
winner = 'tied'
if computer_choice == 3:
if player_choice == "1":
print('Rock smashes scissors. You win!')
winner = 'player'
elif player_choice == "2":
print("Scissors cuts paper. The computer wins!")
winner = 'computer'
else:
print('The game is tied. Try again.')
winner = 'tied'
return winner
def display_menu():
choice2 = 0
number_of_tied_games = 0
number_of_player_games = 0
number_of_computer_games = 0
print(' MENU')
print('1) Rock')
print('2) Paper')
print('3) Scissors')
print('4) Quit')
print("Let's play the game of Rock, Paper, Scissors.")
computer_choice = process_computer_choice()
player_choice = process_player_choice()
while choice2 != "4":
if computer_choice == 1:
print('The computer chooses rock.')
elif computer_choice == 2:
print('The computer chooses paper.')
else:
print('The computer chooses scissors.')
#display player choice
if player_choice == "1":
print('You choose rock.')
elif player_choice == "2":
print('You choose paper.')
else:
print('You choose scissors.')
result = determine_winner(player_choice, computer_choice, choice2)
if result == 'computer':
number_of_computer_games += 1
elif result == 'player':
number_of_player_games += 1
else:
number_of_tied_games += 1
print
main()