Project: Number guessing game
Write a program where one player picks a number and a second player tries to guess it. The program first asks for the number to guess. Then it keeps asking for guesses. After a wrong guess it prints "Too high - try again:" or "Too low - try again:". It stops only when the guess is right, and then prints how many guesses it took. When you run it, the output should match this format:
Enter the number for the player to guess.
-10
Enter your guess.
10
Too high - try again:
5
Too high - try again:
-200
Too low - try again:
-10
You guessed it in 4 tries.
If the player guesses on the first try, print "You guessed it in 1 try."
Save the file as guess_num.py.
Show a solution
Try the project on your own first. This is one working solution. Press Run, and a box asks for each input. Type the sample values from the project description to see the same output.
These tests check the solution above. They run a copy of the program, kept in PROGRAM, and give it pretend input. The testing tools here are not part of the course yet, so do not worry about how they work. Read the test names and the expected outputs: together they list what the program must do. Press Run to run the tests.
Projects run on your own computer, so you tell us when you are done.