On Mon, Dec 8, 2008 at 11:32 PM, simonh <[EMAIL PROTECTED]> wrote:
> That works fine. Then I've tried to use functions instead. The first
> two work fine, the third fails:

[ ... snip ... ]

Try this:

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

def getAge():
   while True:
      try:
         return int(input('Please enter your age: '))
      except ValueError:
         print('That was not a valid number. Please try again.')

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

      return False

name = getName()
age = getAge()
if checkAge(age):
   # Do something
else:
   # Do something else


cheers
James

PS: Read the Tutorial :)

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to