If condition in Python not working as expected? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

If condition in Python not working as expected?

The if condition doesn't work for two arguments i.e. quit or exit The problematic code is placed after the user input ( variable answer ) import random cond = True while cond: choiceList = ["rock", "paper", "scissors"] guess = random.choice(choiceList) score = 0 computer = 0 # asking input for the guess answer = input("\nYou choose: ") """ This doen't work for both conditions quit or exit """ """ More specifically it doesn't take two arguements """ """ quit as well as exit, but works completely fine for either one """ if(answer != "quit" or answer != "exit"): print("Computer choose: " + guess) if(answer == "quit" or answer == "exit"): cond = False else: print("Please input correct option!")

13th Aug 2020, 11:32 AM
Adarsh Mamgain
Adarsh Mamgain - avatar
3 Answers
+ 2
Your first if statement will always evaluate true...
13th Aug 2020, 11:39 AM
Arnesh
Arnesh - avatar
+ 2
yes as Arnesh said, theres no false in that statement maybe try use 'and' instead of 'or'
13th Aug 2020, 11:53 AM
Taste
Taste - avatar
+ 1
Why are you checking condition - "if input is not "quit or "exit" If you wrote condition below - "if input is quit or exit, break loop" This makes no sense, maybe you wanted to show computer choice ONLY if user input ISN'T exit or quit. But at Sololearn codeplayground it also makes no sense, because user makes input only once.. And it would be more appropriate if you replace "while" loop with simple if.
13th Aug 2020, 12:07 PM
Monat15
Monat15 - avatar