Search code examples
pythonpython-3.xif-statement

Getting an if/else statement to read from a list after a user imputs a certain piece of information


super new to python, and just trying out a few if else statements on my own. I wanted to try and make an if/else which reacted to user inputs, but all im getting back is the else statement at the bottom, and not one of the other statements. i've been looking around and cant find an answer as to what im messing up. thank you for any assistance you can give!

below is the code I wrote out:

user_answer = input("are you a male, or a female?:")
 male = ["male", "Male", "MALE"]
female = ["female", "Female", "FEMALE"]
if user_answer == male:
    print("oh well thats awesome to hear! hello sir!")
elif user_answer == female:
    print("oh sick, nice to meet you miss")
else:
    print("im sorry, but that is not a valid entry")`

what I was expecting to happen was it to give me the first if statement if I typed in either male, Male, or MALE into the input, and the same for the elif but for female. however all it is giving me is the else statement


Solution

  • Rather than figuring out what are the expected combinations of upper and lower case letters that a user might enter, it would be better to just change the input to lower case and check for words in lower case:

    user_answer = input("are you a male, or a female?:").lower()
    if user_answer == 'male':
        print("oh well that's awesome to hear! hello sir!")
    elif user_answer == 'female':
        print("oh sick, nice to meet you miss")
    else:
        print("I'm sorry, but that is not a valid entry")