0

Help me fix this problem or "BUG"???

Do you know what is wrong with this code? When I RUN it on My LAPTOP and then i input a random/wrong input for the user_input variable, the while loop breaks, i don't want it, i want the code to print "Wrong input". Then, when i change the 23rd line to: if user_input == "end": The code will succesfully print "Wrong input", but i don't want to change the 23rd line, i still want to give the user more option to break the loop. while True: user_input = input("Command: ") if user_input == "+": a = int(input("1st Number: ")) b = int(input("2nd Number: ")) print(a+b) continue if user_input == "*": a = int(input("1st Number: ")) b = int(input("2nd Number: ")) print(a*b) continue if user_input == "/": a = int(input("1st Number: ")) b = int(input("2nd Number: ")) print(a*b) continue if user_input == "-": a = int(input("1st Number: ")) b = int(input("2nd Number: ")) print(a*b) continue if user_input == "exit" or "quit" or "end": break else: print("Wrong input") continue

24th Mar 2019, 9:33 AM
Fajar Kurniawan
2 Answers
+ 5
if user_input == "exit" or "quit" or "end": evaluates as (user_input == "exit") or ("quit") or ("end") in which string literals such as "quit" and "end" are true. You have to do: if user_input == "exit" or user_input == "quit" or user_input == "end":
24th Mar 2019, 10:35 AM
Hatsy Rei
Hatsy Rei - avatar
0
Thanks
2nd Apr 2019, 9:49 AM
Fajar Kurniawan