Beginner trying to understand functions.
simonh
simonharrison.uk at googlemail.com
Tue Dec 9 06:21:29 EST 2008
Thanks for the extra tips Ivan and Bruno. Here is how the program
looks now. Any problems?
import sys
def get_name():
name = input('Please enter your name: ')
print('Hello', name)
def get_age():
try:
return int(input('Please enter your age: '))
except ValueError:
print('That was not a valid number. Please try again.')
return get_age()
def check_age(age,min=18,max=31):
if age < min:
print('Sorry, too young.')
elif age >= max:
print('Sorry, too old.')
else:
print('Come on in!')
def again():
response = input('Try again? Y or N: ')
while response != "Y":
if response == 'N':
print('Program finished.')
input('Press any key to exit.')
sys.exit()
else:
return response
run()
def run():
get_name()
a = get_age()
check_age(a)
again()
run()
More information about the Python-list
mailing list