mardi 29 décembre 2015

If string statement: What am I missing? [duplicate]

This question already has an answer here:

I've created a simple code which looks like this:

name = str(input ("What is your name?"))

gender = str(input ("What is your gender?"))

if gender == 'male' or 'Male':

    print ("Hello Mr %s" % (name))

elif gender == 'female' or 'Female':

    print ("Hello Mrs %s" % (name))

else:

    print ('Invalid gender. Please try again.')

However, no matter what gender I type (even random words like test), it always prints out the if statement, which means it satisfy the gender == male portion. Like if I key in female, the if statements still prints out. What am I missing here?

Aucun commentaire:

Enregistrer un commentaire