You will notice that, in this code, we are associating rock, paper, and scissors with the numbers 1, 2 and 3, respectively. This means that you can use arithmetic to tell who wins. If subtracting the computer's choice from the player's choice yields a result of 2 or -1, then that means the computer won.
import random choices = ("Rock", "Paper", "Scissors") player_message = "" """ Take a moment here to think of the different pieces of information that your program will be using in order to execute in the intended manner. Information such as... -The human player's name -The human player's choice (as a number and as a string) -The computer player's choice (as a number and as a string) -And so forth... """ player_name = input("What is your name? ") player_choice_num = int (input ("1 = Rock\n2 = Paper\n3 = Scissors\nPlease choose 1, 2, or 3: ")) player_choice = choices[player_choice_num - 1] print() computer_choice_num = random.randint(1, 3) computer_choice = choices[computer_choice_num - 1] """ If the player and computer are tied OR the computer is beating the player, then... Ask the user if he is sure about his choice, as a yes/no If the answer is no, then... Repeat the lines of code that got the user's choice the first time """ # YOUR CODE GOES HERE print (player_name + ", you chose " + player_choice) print ("The computer chose " + computer_choice) print () """ If the player and computer made the same choice, then... Announce that it's a tie. Otherwise, based upon the player's and computer's respective choices, announce what beats what and and tell the player whether he wins or loses. NOTE: Your task in this section is NOT to print out the announcement for who wins or loses. Instead, you should simply assign a string to the variable "player_message", which is printed at the end at the end of the program. """ # YOUR CODE GOES HERE print (player_message)Your task, then, is to follow the directions in the comments in order to direct the program to carry out the appropriate steps depending on various conditions. Note that because some values are being assigned at random or based on user input, the output will look different each time you run the program. To this end, I have provided multiple examples of how the output could look.
What is your name? Bob 1 = Rock 2 = Paper 3 = Scissors Please choose 1, 2, or 3: 1 Bob, are you SURE you want to choose Rock? (Yes or No) Yes Bob, you chose Rock. The computer chose Rock. Bob, you and the computer both chose Rock, so it's a tie.(Bob and the computer chose the same thing, so the program prompted him to confirm his choice. He said "Yes", so the result turned out to be a tie. If Bob changed his choice, he would have either won or lost.)
What is your name? Bob 1 = Rock 2 = Paper 3 = Scissors Please choose 1, 2, or 3: 1 Bob, you chose Rock. The computer chose Scissors. Rock breaks Scissors...you win!(Bob made the winning choice, so the program never asked him to confirm his choice.)
What is your name? Bob 1 = Rock 2 = Paper 3 = Scissors Please choose 1, 2, or 3: 3 Bob, are you SURE you want to choose Scissors? (Yes or No) No 1 = Rock 2 = Paper 3 = Scissors Please choose 1, 2, or 3: 2 Bob, you chose Paper. The computer chose Scissors. Scissors cut Paper...you lose!(Bob and the computer chose the same thing (Scissors), so the program prompted him to confirm his choice. He said "No", so he got the chance to change his choice. He chose Paper instead, so he lost; if he had chosen Rock the second time, he would have won. If he had kept his original choice it would have been a tie.)