-5

I am creating a text based game and asked for the gender. But it seems as if my else statement is not working.

def genderask ():
gender = input ("Are you a he or a she?")
try:
    if gender == "he" or "she":
        print("Hello, ", name)
    else:
        print("Your answer was not he or she.")
        print
        genderask ()
except ValueError:
    print ("Your answer was not he or she.")
    print
    genderask

print genderask ()

Toxxic
  • 57
  • 1
  • 1
  • 6
  • A great thing about Python is that the *expressions* used in an if or else statement can always be evaluated on their own. At the Python interactive prompt try entering just: `gender = 'she'`; then `gender == 'he' or 'she'`. Of for that matter, just see what the expression `'he' or 'she'` does by itself. – Iguananaut Feb 24 '15 at 21:26
  • Note that under no circumstances will that code throw a `ValueError`. – jonrsharpe Feb 24 '15 at 21:31

1 Answers1

0

if gender == "he" or gender == "she":

Pavel Chernikov
  • 2,186
  • 1
  • 20
  • 37