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

How do I have multiple optional inputs?

import time

x = input("Buy Eggs? (Y/N) ")

if x.lower().strip() == "yes" or "y":
    print("Buy Eggs")
    time.sleep(0.5)
    print("You bought eggs")

elif x.lower().strip() == "no" or "n":
    print("Don't buy eggs")
    time.sleep(.5)
    print("You don't have eggs")

What I want to happen is to allow multiple words to be inputted for one if command. I thought it’d work but instead of working it would prioritize the top piece of code.

Buy Eggs? (Y/N) n #<--- Answer#
Buy Eggs
You bought eggs

Process finished with exit code 0

It only seems to work if I remove the or command but I haven’t found any other options to allow multiple optional inputs.

Thank you if you do choose to help me

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 :

Hope this can help you:

ans = input("Buy Eggs? (Y/N) ")

if ans.lower().strip() in ('y', 'yes'):
    print("Buy Eggs")
    time.sleep(0.5)
    print("You bought eggs")

elif ans.lower().strip() in ('n', 'no'):
    print("Don't buy eggs")
    time.sleep(.5)
    print("You don't have eggs")
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