Question
Convert the user input strings to lower case so that you only have to check lower case in your test. Hint: look at the lower()
- Convert the user input strings to lower case so that you only have to check lower case in your test. Hint: look at the lower() function in Python.
- Create a loop for each input that does the following:
- Check the value of the input
- If the value is not correct, alert the user
- Give the user a total of three chances to get it right
- If they don't get it right in three tries, use sys.exit to exit the code and give them a message that they exceeded their allowable number of tries
import sys
# Get User input player1 = input('Enter Value for Player 1: ') if (player1 != 'rock' and player1 != 'paper' and player1 != 'scissors'): print('Player1 input incorrect') sys.exit('Input Error') player2 = input('Enter Value for Player 2: ') if (player2 != 'rock' and player2 != 'paper' and player2 != 'scissors'): print('Player2 input incorrect') sys.exit('Input Error') # Game logic. # Note that the backslash is a line continuation for long expressions if (player1 == 'rock' or player1 == 'paper' or player1 == 'scissors') \ and (player2 == 'rock' or player2 == 'paper' or player2 == 'scissors'): if player1 == player2: print ('Players Tie') elif (player1 == 'rock' and player2 == 'scissors') \ or (player1 == 'paper' and player2 == 'rock') \ or (player1 == 'scissors' and player2 == 'paper'): print('Player 1 Wins') else: print('player 2 wins') else: print('Input Incorrect')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started