Beginner trying to understand functions.

simonh at
Mon Dec 8 19:02:05 CET 2008

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

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

def getAge():
    while True:
            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.')

a = getAge()

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

More information about the Python-list mailing list