Ivan Illarionov <[EMAIL PROTECTED]> writes:

> On Dec 8, 9:02 pm, simonh <[EMAIL PROTECTED]> wrote:
>> Thanks for the many replies. Thanks especially to Pierre. This works
>> perfectly:
>
> <snip>
>
>> 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.')
>
> You could also drop the while loop and the 'age' variable:
>
> def getAge():
>     try:
>         return int(input('Please enter your age: '))
>     except ValueError:
>         print('That was not a valid number. Please try again.')
>         return getAge()

That's not necessarily good advice as Python does not optimize
tail-calls.

-- 
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to