[Tutor] Guess my number game
alan.gauld at btinternet.com
Sat Nov 19 17:46:58 CET 2011
On 19/11/11 12:53, myles broomes wrote:
> ...Here is the pseudocode I have written up:
> Once the user has thought of their number, take a guess
> While the number has not been guessed correctly
> Increase the number of 'tries' by 1
> Ask the user if the guess was too high or too low
> If the guess was too high
> guess lower
> If the guess was too low
> guess higher
> Once the number has been guessed correctly, tell the user the number of tries it took
Your pseudocode looks fine.
Try writing that as Python.
You'll need to use raw_input() if using python 2 or input() in Python 3
You will want to convert the input to an int()
You will want to use the random module, and probably the randrange
function within it.
You will need variables to store the number of tries and the latest guess,
Try it. If you get stuck show us what you've done, any error messages
and tell us what you don't understand.
Author of the Learn to Program web site
More information about the Tutor