On Wed, 27 Jul 2011 20:16:31 -0400 Alexander Quest <alexxqu...@gmail.com> 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! > > -Alex There are probably better ways but this worked for me: x=range(1,50) mid=x[len(x)/2] You do have to keep in mind the way python counts list indices for a range call - i.e. x=range(1,50) will give you a list with all numbers 1 to 49 in it. Hope that helps! tom _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor