nmp153
nmp153

Reputation: 3

My If Statements in Python are not working

I am new to python and I am writing a program to play Rock, Paper, Scissor. When I start to do the if else statements to compare outputs from user and the computer, my program just completely skips the if-else statements. Not sure what's going on with it.

user = input("Please enter Rock, Paper, Scissor: ")
while user not in ("Rock", "Paper", "Scissor"):
      print("Try again")
      user = input("Please enter Rock, Paper, Scissor: ")


if user == "Rock":
   print("Your Choice is Rock")
elif user == "Scissor":
   print("Your Choice is Scissor")
elif user == "Paper":
   print("Your Choice is Paper")


import random
AI=["Rock", "Paper", "Scissor"]
b=random.randint(0,2)
print("The computer choice is " + AI[b])

if user == b:
   print("Tie")
elif user == "Rock":
   if b == "Scissor":
      print("Rock Beats Scissor")

It goes through all of the code expect the last if-else statement. It just finishes the program after the computer chooses what to use.

Upvotes: 0

Views: 92

Answers (1)

Yasiel Cabrera
Yasiel Cabrera

Reputation: 598

Your issue is in the last if, you are comparing a string with a integer user == b remember that the user choice is a string but b is a random number between 0 and 2.

if user == AI[b]:  # you need to compare the value with the string selection of the "AI"
   print("Tie")
elif user == "Rock":
   if AI[b] == "Scissor":
      print("Rock Beats Scissor")
else:
   # I don't remember what are the rules to win or lose LOL, but I guess there are more
   # maybe you need more conditions
   print("other choice...")

Upvotes: 1

Related Questions