Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is my **or** statement not working as I want?

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.Burger\n 2.McPuff\n 3.Ice Cream\n 4.Cold Drink\n\nPlease 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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Instead of if repeat == "No" or "no", use:

if repeat == "No" or repeat == "no"

Or even:

if repeat in ("No", "no")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading