Help With If and Elif and Else

Question:
When I don’t have my else statement in it the code breaks but when I have my ELSE statement in it, it always prints an error. Any ideas?
Repl link:
https://replit.com/@Chandler0Bing/Rock-Paper-Scissors-Vs-A-Computer
Picture:
image

else:
    print('\n\nAn Error Has Occurred Try Typing R or P or S :>')
1 Like

Remove the a = true and change while a == 'true' to

while True

then, add an else to each if

and you have two if’s at the top so make one an elif. There is an easier way to do this part but you would have to change a lot of the code.

Instead of using or you can just check for the first letter of person.lower():

if person.lower()[0] == 'r' and computer == 1:
  # code here
elif person.lower()[0] == 'p' and computer == 2:
  # ...

Also like @JayAySeaOhBee14 said, remove a = 'true' and just use while True: instead.

1 Like

This is brilliant. I will now use input_var.lower()[0] instead of comparing to a list of words that mean “yes” and “no”.

1 Like