Saturday, December 17, 2016

Programming Projects for Beginners - Guess the Number

This is a game where the computer selects a random number (say, between 0 and 10, to keep it simple), and the user guesses the number.

Note: If you stumbled upon this post and are wondering what this is about, start here.

Here is the usecase:
- Program picks a random number
- Program asks user to guess it
- User enters a guess
- Program tells user if (a) it is the correct guess (b) too high [say, if the guessed number is 5+- spaces away](c) too low (d) bit high or (e) bit low
- User guesses again until the answer is found

Programming constructs used:
- User input
- Libraries
- Comparison
- Looping
- Conditional statements
- Error handling

Here is what a sample output would look like:

As you notice above, I ran the program several times to give you a flavor of the output.

Handle invalid input as seen in the example above.
Count the number of tries the user takes and make an appropriate comment about it (as seen in the example).

Happy coding!