This should be done in Python 3.5.2 Rock-Paper-Scissors-Lizard-Spock Write a gam
ID: 3778415 • Letter: T
Question
This should be done in Python 3.5.2
Rock-Paper-Scissors-Lizard-Spock
Write a game of Rock-Paper-Scissors-Lizard-Spock that meets the following requirements:
Support player-versus-computer play, and have adequate user instructions.
Loop after each round to ask if the player wants to continue.
On each round the results are displayed prior to asking if the player wants to continue playing.
The results of each round must be the same text as described in the rules for winning the game below. There should also be text stating if the player or computer wins.
Keep count of how many time the user won and lost. When the user chooses to quit, print the total number of wins and loses.
The rules for winning the game are as follows. Please note that in the following list, the left-side choice is the winner. Please keep in mind that the if the player choice and the calculated computer choice are the same, that results in a tie.
Scissors cut Paper
Paper covers Rock
Rock crushes Lizard
Lizard poisons Spock
Spock smashes Scissors
Scissors decapitate Lizard
Lizard eats Paper
Paper disproves Spock
Spock vaporizes Rock
Rock crushes Scissors
Explanation / Answer
def number_to_choice(number): if number == 0: return "rock" elif number == 1: return "spock" elif number == 2: return "paper" elif number == 3: return "lizard" else: return "scissors" def choice_to_number(choice): if choice == "rock": return 0 elif choice == "spock": return 1 elif choice == "paper": return 2 elif choice == "lizard": return 3 else: return 4 def rpsls_game(player_choice): # change player choice to number using choice_to_number function player_number = choice_to_number(player_choice) # generating random number for computer computer_number = random.randint(0, 5) # compute difference of player_number and computer_number modulo five diff = (player_number - computer_number) % 5 # change computer_number to choice using number_to_choice function computer_choice = number_to_choice(computer_number) get_result(player_choice, computer_choice, diff) def get_result(player_choice, computer_choice, diff): global PLAYER_WIN_COUNT global PLAYER_LOSE_COUNT global PLAYER_DRAW_COUNT print("Player choice is :", player_choice) print("Computer choice is:", computer_choice) if diff == 1 or diff == 2: print("Player wins!") PLAYER_WIN_COUNT += 1 elif diff == 3 or diff == 4: print("Computer wins!") PLAYER_LOSE_COUNT += 1; else: print("Tie!") PLAYER_DRAW_COUNT += 1 def start_gmae(): flag = False while True: if flag == True: break; choice = input("Your Choice:") rpsls_game(choice) opt = input("You want to continue(Y,N):").upper() while True: if opt == "Y": flag = False break; elif opt == "N": flag = True print("Bye Bye") print("Number Of Win:", PLAYER_WIN_COUNT) print("Number Of Lose:", PLAYER_LOSE_COUNT) print("Number Of Draw:", PLAYER_DRAW_COUNT) break else: opt = input("You want to continue(Y,N):").upper() if __name__ == "__main__": import random PLAYER_WIN_COUNT = 0 PLAYER_LOSE_COUNT = 0 PLAYER_DRAW_COUNT = 0 start_gmae()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.