Beginner trying to understand functions.
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Tue Dec 9 10:17:02 CET 2008
simonh a écrit :
> Thanks for the many replies. Thanks especially to Pierre. This works
> perfectly:
>
(snip)
Ok, now for some algorithmic stuff:
> 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.')
if age is neither greater than max nor lesser than min, then it's it in
range(min, max). IOW, you could just skip the first test:
def checkAge(age,min=18,max=31):
if age < min:
print('Sorry, too young.')
elif age >= max:
print('Sorry, too old.')
else:
print('Come on in!')
!-)
More information about the Python-list
mailing list