Why is my **or** statement not working as I want?
Question:
import time
repeat=0
price=0
print("Welcome to McDonald's self order system")
time.sleep(0.5)
name_person=str(input("nPlease enter your name to continue: "))
while True:
order=int(input("n---Menu---n 1.Burgern 2.McPuffn 3.Ice Creamn 4.Cold DrinknnPlease order by typing the number: "))
if order in range(1,4) :
repeat=str(input("Do you want to order more? Yes/No: "))
if repeat == "No" or "no":
print("Ok")
break
else :
print("n!!Invalid input!!")
time.sleep(0.5)
The or command is not working when I am typing No its shows Ok that’s normal but if I type Yes it should loop but then also its showing Ok and when I am typing anything its giving the output Ok but if I am removing the or its working perfectly.
Please help me with this situation
Answers:
Instead of if repeat == "No" or "no"
, use:
if repeat == "No" or repeat == "no"
Or even:
if repeat in ("No", "no")
import time
repeat=0
price=0
print("Welcome to McDonald's self order system")
time.sleep(0.5)
name_person=str(input("nPlease enter your name to continue: "))
while True:
order=int(input("n---Menu---n 1.Burgern 2.McPuffn 3.Ice Creamn 4.Cold DrinknnPlease order by typing the number: "))
if order in range(1,4) :
repeat=str(input("Do you want to order more? Yes/No: "))
if repeat == "No" or "no":
print("Ok")
break
else :
print("n!!Invalid input!!")
time.sleep(0.5)
The or command is not working when I am typing No its shows Ok that’s normal but if I type Yes it should loop but then also its showing Ok and when I am typing anything its giving the output Ok but if I am removing the or its working perfectly.
Please help me with this situation
Instead of if repeat == "No" or "no"
, use:
if repeat == "No" or repeat == "no"
Or even:
if repeat in ("No", "no")