On 01/06/2012 03:05 PM, Garland W. Binns wrote:
Hello, I have been experimenting with trying to rewrite the following
script so that a computer tries to guess a number I'm thinking of:
https://gist.github.com/1572067

I was thinking that basically I need to create a while loop, and somehow
redefine the randrange depending on whether or not I provide raw input
saying that the guess is higher or lower.

  Can anyone offer any suggestions?

-
Sure.  Start from scratch.

Seriously, the program you're desiring has little to do with the one you already wrote, other than probably using print and raw_input. The optimal answer doesn't even need any random calls in it.

Are you familiar with the concept of binary search? That's what you should implement.

Take a crack at it, and see what you come up with.

Hint: think of a way to express the thinking part (the alogorithm) as a function, and write that first. Then you just write something that controls its calls to the function based on user input.

--

DaveA

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to