Untitled
unknown
python
3 years ago
3.5 kB
6
Indexable
import sys #import sys to make sure sys.exit works answers = ["rock","paper","scissors"] #make a list of the possible correct answers attempts_player1 = 0; #make a variable that holds the number of attempts for player 1 attempts_player2 = 0; #make a variable that holds the number of attempts for player 2 print("Welcome to Rock, Paper, Scissors: ") #print an introductory message print("Player 1, type 'rock', 'paper', or 'scissors'") #prompt Player 1 to type in their choice player1 = input().lower() #declare player1 and take input from user and make it lowercase while (player1 not in answers): #while player1 is not equal to the items in the list 'answers' print('Player 1 input is incorrect. Enter input again ') #print that input is incorrect player1 = input().lower() #take input again for player 1 and make it lowercase attempts_player1 += 1 #iterate the attempts_player1 variable by 1 for each time the loop runs if (attempts_player1 == 3): #check to see if the attempts_player1 is equals to 3, if it is then uses sys.exit to exit the program. sys.exit("Player 1 exceeded maximum number of tries.") #exits the program while displaying a message print("Player 2, type 'rock', 'paper', or 'scissors'") #prompt Player 2 to type in their choice player2 = input().lower() while (player2 not in answers): #while player2 is not equal to the items in the list 'answers' print('Player 2 input is incorrect. Enter input again ') #print that input is incorrect player2 = input().lower() #take input again for player 2 and make it lowercase attempts_player2 += 1 #iterate the attempts_player2 variable by 1 for each time the loop runs if (attempts_player2 == 3): #check to see if the attempts_player2 is equals to 3, if it is then uses sys.exit to exit the program. sys.exit("Player 2 exceeded maximum number of tries.") #exits the program while displaying a message if (player1 == player2): print("The game is a draw because both player 1 and 2 chose:", player1) #print that the game is a draw and also the input of either player 1 or 2 elif (player1 == "rock"): #if player 1's input is 'rock' if (player2 == "paper"): #and if player 2's input is 'paper' print("Player 2 wins because they chose: ", player2) #print that player 2 wins because paper beats rock. elif (player2 == "scissors"): #and if player 2's input is 'scissors' print("Player 1 wins because they chose: ", player1) #print that player 1 wins because rock beats scissors. elif (player1 == "paper"): #else if player 1's input is 'paper' if (player2 == "rock"): #and if player 2's input is 'rock' print("Player 1 wins because they chose: ", player1) #print that player 1 wins because paper beats rock. elif (player2 == "scissors"): #and if player 2's input is 'scissors' print("Player 2 wins because they chose: ", player2) #print that player 2 wins because scissors beats paper. elif (player1 == "scissors"): #if player 1's input is 'scissors' if (player2 == "rock"): #and if player 2's input is 'rock' print("Player 2 wins because they chose: ", player2) #print that player 2 wins because rock beats scissors. elif (player2 == "paper"): #and if player 2's input is 'paper' print("Player 1 wins because they chose: ", player1) #print that player 1 wins because scissors beats paper.
Editor is loading...