Can you assign multiple strings to the same variable on the same line?

I’m having trouble writing a program that asks for your birthday and then the user can confirm if their inputted birthday is true or false (yes or no), however, I want to be able to accept an answer of "yes" if it was spelt with an accidental capital visa Veras for "no"

For example if I were to input "Yes" instead of "yes" as an answer to whether or not the correct birthday is being displayed in the console, the computer would still accept that as an answer as the word is still spelt correctly.

So in that case, I am trying to understand if I can assign multiple ways of spelling "yes" to one variable so I don’t have to type all the ways you can write the word "yes" and assign it too different variables.

Here is what I have tried for my code:

answer_YES = 'Yes' or "yes"
answer_NO = 'No' 

Name = input("What's your name? ")
Last_Name = input("What's your last name? ")
print("\nHello,", Name, Last_Name + "!")

num1 = float(input("Give me one number: "))
num2 = float(input("Give me a better number: "))

print("\nHere is your Summary:")
print(int(num1), '+', int(num2), '=', int(num1 + num2))

BD = input("\nOK, now give me your birthday m/d/y: ")
print("Is this your birthday?", '"' + BD + '"' "\n\nCorrect? (Yes) Incorrect? (No)\n")
answer = input("Answer: ")

#Using Boolean Expressions

if answer == answer_YES:
    print("Awesome! Thank you", Name)

>Solution :

if it is all about the yes spelling (Yes or YEs or YES …)
you can have

anser_YES = 'yes'

then in the validation you do something like

if answer.lower() == answer_YES

otherway if you want make multilang input accept you can use list of accepted answers, so
instead of

answer_YES = 'yes'


answer_YES = ['yes', 'oui', 'Yeeeeeessss']

then to test the true response do

if answer in answer_YES:

i wish this was helpful for you

Leave a Reply