rafie
rafie

Reputation: 1

How can i put more options for the user to enter in python?

I want to edit this code and allow the user to enter either: Yes | No, Y | y, or N | n!

Can somebody help me please?

answer = input ("Is your data correct? Please say Y or N only! : ")

if answer == "Y":
    print("Thankyou!")
else:
    print("Please re-enter your data again!")

Upvotes: 0

Views: 42

Answers (1)

user2390182
user2390182

Reputation: 73498

This should cover all your cases:

if answer.lower().startswith("y"):

Convert to lower case and just check the first letter. If you want to really limit the answer to variations of y and yes, you could do:

if answer.lower() in ("y", "yes"):

Upvotes: 4

Related Questions