Search code examples
pythonlowercase

Why writing a correct input uppercase throws an error?


If user inputs a correct word uppercase I get a "You made a mistake" response. Why does user_choice.lower() not work like I intended? Where did I make a mistake?

import random

rock_paper_scissors = ("rock", "paper","scissors")
cpu_choice = random.choice(rock_paper_scissors)
user_choice = input("Rock, paper or scissors ? Enter your choice: ")


if user_choice.lower() != "rock" or "paper" or "scissors":
    print("You made a mistake. Please try again")
    user_choice = input("Rock, paper or scissors ? Enter your choice: ")

while cpu_choice == user_choice.lower():
    print ("--------------------------------------------------------")
    print(f"CPU: {cpu_choice.upper()} vs YOU: {user_choice.upper()}.  It's a tie. Try again!")
    print ("--------------------------------------------------------")
    user_choice = input("Rock, paper or scissors ? Enter your choice: ")

Solution

  • The condition if you set isn't correct. Try instead

    if user_choice.lower() != "rock" or user_choice.lower() != "paper" or user_choice.lower() != "scissors":