Beginner trying to understand functions.

simonh simonharrison.uk at googlemail.com
Mon Dec 8 19:02:05 CET 2008


Thanks for the many replies. Thanks especially to Pierre. This works
perfectly:

def getName():
    name = input('Please enter your name: ')
    print('Hello', name)

def getAge():
    while True:
        try:
            age = int(input('Please enter your age: '))
            return age

        except ValueError:
            print('That was not a valid number. Please try again.')

def checkAge(age,min=18,max=31):
    if age in list(range(min, max)):
        print('Come on in!')
    elif age < min:
        print('Sorry, too young.')
    elif age >= max:
        print('Sorry, too old.')

getName()
a = getAge()
checkAge(a)


I am running Python 3, sorry for not stating that originally.



More information about the Python-list mailing list