Write a Python script that generates a random integer between 1 and 10 and prompts the user to enter a guess at that number. If the guess is incorrect, the program displays, "That is incorrect. Please guess again." When the player enters the correct number, the program displays, "Correct! That took you n guesses.", where n is replaced with the number of total guesses. The following example illustrates how the script should function Guess a number between 1 and 10: 1 That is incorrect. Please guess again: 2 That is incorrect. Please guess again: 3 That is incorrect. Please guess again: 4 Correct! That took you 4 guesses.
Added by Richard S.
Close
Step 1
Import the random module to generate a random integer. Show more…
Show all steps
Your feedback will help us improve your experience
Madhur L and 69 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a program that plays a guessing game with the user. The program should generate a random number between 1 and 100, then prompt the user repeatedly to guess the number. When the user guesses incorrectly, the game should give the user a hint about whether the correct answer is higher or lower than the guess. Once the user guesses correctly, the program should print a message showing the number of guesses that the user made. Sample output: I'm thinking of a number between 1 and 100... Your guess? 50 It's higher. Your guess? 75 It's lower. Your guess? 65 It's lower. Your guess? 60 It's higher. Your guess? 63 It's higher. Your guess? 64 You guessed it in 6 guesses!
Shelayah R.
Write a Python script that will play the Guess the Number game. Before you begin coding, create a flowchart using Draw.io to model the game flow. Include a text box with your name and other descriptive information at the top of your flowchart. Export your flowchart as a PDF file. Your Python program should generate a number between 1 and 100. The program should continue until the user guesses the number successfully. Upon each guess, the program should tell the user if the guess was correct, too high, or too low. Once the user guesses correctly, the program should inform the user how many guesses it took. Be sure to include comments at the top of your Python program with your name and other descriptive information.
Florencia C.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD