Question: Guessing Game This assignment focuses on loops, lists, and numbers. You may use for loops and/or while loops . Write all your code in a
Guessing Game
This assignment focuses on loops, lists, and numbers. You may use for loops and/or while loops. Write all your code in a file named guessing.py. Your program allows the user to play guessing-game where two players participate.
Player 1 has a very simple task: all they need to do is enter a number between 0 and 100 for player 2 to guess. If the number entered is negative, or greater than 100, your program will complain ( see below for example output)
Player 2 must repeatedly guess numbers until they find the one that player 1 chosen. After each incorrect guess, you will tell the user whether to correct answer is lower or higher. Once the correct number is guessed, you will inform player 2 that they guessed the correct number and report how many guesses it took them, and show all the numbers that they guessed in order.
Your program must reproduce exactly the format and behavior of the logs in the this document, and on the sample outputs I will provide. Below are a few example runs of the program:
| Welcome to the guessing game! Player 1: Enter number for Player 2 to guess between 0 and 100: 78 Player 2, guess a number: 50 Too low... Player 2, guess a number: 90 Too high... Player 2, guess a number: 70 Too low... Player 2, guess a number: 80 Too high... Player 2, guess a number: 75 Too low... Player 2, guess a number: 77 Too low... Player 2, guess a number: 78 Correct! It took you 7 tries to guess correctly! The numbers you guessed were: 50 90 70 80 75 77 78 Goodbye! |
| Welcome to the guessing game! Player 1: Enter number for Player 2 to guess between 0 and 100: 12 Player 2, guess a number: 30 Too high... Player 2, guess a number: 20 Too high... Player 2, guess a number: 10 Too low... Player 2, guess a number: 12 Correct! It took you 4 tries to guess correctly! The numbers you guessed were: 30 20 10 12 Goodbye! |
Your output will differ depending on the number entered by player 1 and the numbers guessed by player 2. However, the overall structure should match that shown in the examples.
First, the program prints out a basic introduction.
Next, a guessing game is played. Player 1 enters the number for Player 2 to guess. Then, the game asks Player 2 for guesses until the correct number is guessed. After each incorrect guess, the program gives a clue where the correct number is lower or higher than the guess. Once the user types the correct number, the game ends and the program reports how many guess were needed and all of the guessed numbers. At this point, the program will print a goodbye message and then exit.
Your program should handle the special case where player 2 guesses the correct number on the very first try. Print a message as follows:
| Player 2, guess a number: 30 You got it right in 1 guess! Wow, you are AMAZING. |
You may assume valid user input, however you must validate the numbers entered by player 1. When prompted for numbers player will type integers only and they will be in the proper ranges.
Implementation Guidelines:
Define a variable that establishes the maximum number that player 1 can input for player 2 to guess. This should be 100 by default, but should be something that is changeable. Do not use 100 directly in your code. Instead, declare a constant at the very top of your program 100, and use the variable to check the limit. The example out in this spec shows games from 1 to 100, but your should be able to change the constant value to use other rangers such as from 1 to 50 or any maximum. Use your constant throughout your code and do not refer the number 100 directly. Test your program by changing your constant and running it again to make sure that everything uses the new value.
Read user input using input()
Use while or for loops to produce repetition. Some students try to avoid properly using while loops by using a function that calls itself, or a pair of functions A and B where A calls B and B calls A, creating a cycle of call. Suchar solutions are not appropriate on this assignment and will result in a deduction of points.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
