-2

When I run the program and type gender as anything else but not male or female, the program does not work as expected. I have struggled for a day and can't figure out. Also how can I put the function after its call and still make the program run? I read of a main function but can't figure out how to modify the code with it.

from sys import exit
birthdays = {'Alice': 'April 1', 'Bob': 'Dec 12', 'Carol': 'Mar 4'}

def dateOfBirth():
    bday = raw_input("> ")
    birthdays[name] = bday
    print "Database records updated."
    print "The number of records is now " + str(len(birthdays)) + "."
    print birthday`enter code here`s
    exit(0)

while True:
    print "Enter a name: (blank to quit)"
    name = raw_input("> ")

    if name == '':
        exit(0)

    if name in birthdays:
        print birthdays[name] + " is the birthday of " + name + "."
        exit(0)

    else:
        print "I do not have the birthday information for " + name + "."
        print " What is the sex?"
        gender = raw_input("> ")
        if gender == 'male':
            print "What is his birthday?"
            dateOfBirth()
        elif gender == 'female' or 'Female':
            print "What is her birthday?"
            dateOfBirth()
        else:
            print " The gender is not recognised. Anyway we will continue." 
            dateOfBirth()
chibole
  • 942
  • 6
  • 15

1 Answers1

5

Change this:

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

to this:

elif gender in ('female', 'Female'):

or I would suggest:

elif gender.lower()=='female':

What you have with

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

is essentially else if gender is female, or if the string "Female" is nonempty. That will always be true, whatever the value of gender.

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • Thank you, what about the second part of the question. – chibole Dec 21 '15 at 14:32
  • See for instance [this question](http://stackoverflow.com/questions/22492162/understanding-the-main-method-of-python) for how to use a `main` function. – khelwood Dec 21 '15 at 14:47