Question
python Write a program that plays one game of Rock-Paper-Scissors with the user. Enable your program to handle upper and lower case input. Catch the
python
Write a program that plays one game of Rock-Paper-Scissors with the user. Enable your program to handle upper and lower case input. Catch the error if the user types something other than Rock-Paper-Scissors.
An example of the inputs and outputs might look like this
Computer: Rock, Paper, or Scissors?
User: rock
Computer: You chose Rock and the computer chose Rock Its a Draw!
You will need to use an IF statement for the user, a random function for the computer, and do some string manipulation as well.
NOTE: In order to get a random number for the computer's choice, you will have to use the random module. Here's how you do it:
import random
myRandomNumber = random.random()
whats wrong with my coding? always error
---
import random String1 = 'Rock' String2 = 'Paper' String3 = 'Scissors'
print ("Computer: Rock, Paper, or Scissors") x=input("User:") r=random.randint(1,3) if x.lower()== String1.lower() or x.lower()== String2.lower() or x.lower() == String3.lower(): if r==1: if x.lower() == String1.lower(): print ("You choose Rock and the computer choose Rock. Its a draw. ") elif x.lower() == String2.lower(): print ("You choose paper and the computer choose Rock. You won. ") else: print ("You choose scissors and the computer choose Rock. Computer Won ") elif r==2: if x.lower() == String1.lower(): print ("You choose Rock and the computer choose Paper. Computer Won ") elif x.lower() == String2.lower(): print ("You choose Paper and the computer choose Paper. It's a draw. ") else: print ("You choose Scissors and the computer choose Paper. You Won ") else: if x.lower() == String1.lower(): print ("You choose Rock and the computer choose Scissors. You Won ") elif x.lower() == String2.lower(): print ("You choose Paper and the computer choose Scissors. Computer won. ") else: print ("You choose Scissors and the computer choose Scissors. It's a draw ") else : print (" User has typed something other than rock, scissor or paper !")
----
import random print ("Computer: Rock, Paper, or Scissors") x#input ( "User : " ) r-random. randint (1,3) if x. lower ( ) == String! . lower ( ) or x . lower ( ) == String2. lower ( ) or x. lower ( ) String3. lower ( ) : == if rl: if x.lower -Stringl.lower print ("You choose Rock and the computer choose Rock. It's a draw. ") print ("You choose paper and the computer choose Rock. You won. ) print ("You choose scissors and the computer choose Rock. Computer Won elif x.lower String2.lower else: elif r# 2 : if x.lower-Stringl.lower elif x.lower String2.lower else: print ("You choose Rock and the computer choose Paper. Computer Won") print ("You choose Paper and the computer choose Paper. It's a draw.") print ("You choose Scissors and the computer choose Paper. You Won ) else: if x.lower -Stringl.lower elif x.lower String2.lower else: print ("You choose Rock and the computer choose Scissors. You Won ") print ("You choose Paper and the computer choose Scissors. Computer won. ") print ("You choose Scissors and the computer choose Scissors. It's a draw") else print (" User has typed something other than rock, scissor or paper !")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