[Tutor] check_range
DogWalker
forestiero at qwest.net
Wed Dec 15 06:32:31 CET 2004
"Brian van den Broek" <bvande at po-box.mcgill.ca> said:
>Marc Gartler said unto the world upon 2004-12-14 18:12:
>> Hi all,
>>
>> I am fairly new to both Python & programming, and am attempting to
>> create a function that will test whether some user input is an integer
>> between 10 and 89, but the check isn't happening...
>>
>> def check_range(myrange):
>> if range(myrange) != range(10,89):
>> return "False"
>> else:
>> return "True"
>>
>> ...this gets called later via:
>> if check_range(input):
>> done = "True"
>> return int(input)
>>
[...]
>I have a some style suggestions for you, too.
>
>Try it this way:
>
> >>> def check_in_range(value):
> in_range = False
> if 9 < value < 90:
> in_range = True
> return in_range
>
> >>> check_in_range(35)
>True
>
Shorter:
def check_in_range(value):
return 9 < value < 90
[...]
More information about the Tutor
mailing list