-2

I was trying to adjust this code so it accepts if I wrote rock , paper or scissor in small or capital letter. and if it wasn't one of these three words then it should exit the program and print "WRITE IT CORRECTLY!")

import random
y = input("Enter rock, paper or scissor: ")
x = ["rock","paper","scissor"]
z = random.choice(x)
c = print("Computer: " + str(z) )


if (y=="rock" and z=="scissor"):
    print("YOU WON!")

elif  (y=="rock" and z=="paper"):
    print("COMPUTER WON!")

elif  (y=="rock" and z=="rock"):
    print("TRY AGAIN!")

elif  (y=="paper" and z=="rock"):
      print("YOU WON!")

elif (y=="paper" and z=="paper"):
    print("TRY AGAIN!")

elif (y=="paper" and z=="scissor"):
    print("COMPUTER WON!")

elif (y=="scissor" and z=="rock"):
    print("COMPUTER WON!")
Thierry Lathuille
  • 23,663
  • 10
  • 44
  • 50
Mariam
  • 1
  • 2

4 Answers4

0

Use

y = y.lower()

This will change everything in the input to lowercase and helps you with the program!

Ananth
  • 815
  • 1
  • 4
  • 11
0

You need to check the value of the user input after you receive it.

y = input("Enter rock, paper or scissor: ")
if y.lower() not in ["rock", "paper", "scissor"]:
    print("WRITE IT CORRECTLY!)

Put this in a loop to repeat until you receive an expected value, then continue on with the application.

TeleNoob
  • 48
  • 1
  • 10
0
y = input("Enter rock, paper or scissor: ").lower()

if y not in x:

    print("Write it correctly!")
Berly
  • 33
  • 4
0

You can use another “if” to check for the input value before .

if y not in x:
   print ("WRITE IT CORRECTLY!")
else:
   #continue with current code
TeleNoob
  • 48
  • 1
  • 10