[Tutor] check_range
Kent Johnson
kent37 at tds.net
Wed Dec 15 00:46:26 CET 2004
You misunderstand what range() does. It returns a list of numbers starting with the lower one and up
to but not including the upper one:
>>> range(5)
[0, 1, 2, 3, 4]
>>> range(5, 10)
[5, 6, 7, 8, 9]
To test for a number in a range you can use 10 < n < 90:
>>> x = 1
>>> 10 < x < 90
False
>>> x = 15
>>> 10 < x < 90
True
>>> x = 100
>>> 10 < x < 90
False
Kent
Marc Gartler wrote:
> 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)
>
>
> What am I doing wrong?
>
> Thanks!
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list