[Tutor] Assigning range

Alexander Quest redacted@example.com
Thu Jul 28 02:45:50 CEST 2011


Thanks Steven- I'll try that out.

-Alex

On Wed, Jul 27, 2011 at 5:40 PM, Steven D'Aprano <steve at pearwood.info>wrote:

> Alexander Quest wrote:
>
>> Does anyone know how to assign a certain numerical range to a variable,
>> and
>> then choose the number that is the middle of that range? For example, I
>> want
>> to assign the variable "X" a range between 1 and 50, and then I want to
>> have
>> the middle of that range (25) return with some command when I call it
>> (perhaps rangemid or something like that?). In pseudocode, I am trying to
>> say X = range [1,50], return middle of range (which should return 25) but
>> I
>> don't know how to code it. This is for a basic program I'm trying to write
>> where the player thinks of a number and the computer tries to guess the
>> number in as few tries as possible. Thanks for any help!
>>
>
>
> Forget about using range, that just adds meaningless complexity.
>
> What is important is that you have a lower bound, and a higher bound: two
> numbers, instead of how ever many (possible thousands, or millions!) in
> range(low, high).
>
> middle = (low+high)//2
>
>
>
> --
> Steven
>
> ______________________________**_________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110727/840d70a1/attachment.html>


More information about the Tutor mailing list
l>