Computer Guesses Your Number!

Well, after “Guess the Number”, it seemed logical to write a program that let’s the computer guess your number!

The program starts with some instructions, then we import random and time. Time allows us to make the program pause for 2 seconds before making its first guess. This gives the user a bit of time to actually think of a number!

We set some initial variables and then enter the main loop of the game. I had to make a string including the guess converted to a string, because the input() function only works with strings. If the user doesn’t type y, l or h, we use the “continue” command to go back to the top of the while loop.

I’ve used random numbers to make the computer’s guesses a bit more realistic. We set “high” and “low” to whatever the upper and lower limits are, based on the user’s responses to the guesses made so far.

If you can think of any ways to improve this game, please let me know in a comment!

happy coding



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: