Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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()

  1. 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.
  2. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

Discuss some of the concerns about the future of Social Security.

Answered: 1 week ago