Have the computer select a random number with the following commands: from random import randint print(“”) num = randint(1,9) user_guess = 0 Create a loop that will check to see if the user_guess is the same as the random number while user_guess != num: Inside the loop get a guess from the user and check to see if the guess is lower than the number user_guess = int(input(“Enter a guess from 1 to 9: “)) if user_guess < num: print(“Guess is low”) elif user_guess > num: print(“Guess is high”) else: print(“You guessed it!”)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

This is python. I attached my current code as a picture. My "Guess is low" and "Guess is high" wont work. But if I guess the correct number it works. Here are the instructions.

Open the Python 3.10 Integrated Development Learning Environment (IDLE) and create a new project
named, GuessNumber
Have the computer select a random number with the following commands:
from random import randint
print(“<Your Student number>”)
num = randint(1,9)
user_guess = 0
Create a loop that will check to see if the user_guess is the same as the random number
while user_guess != num:
Inside the loop get a guess from the user and check to see if the guess is lower than the number
user_guess = int(input(“Enter a guess from 1 to 9: “))
if user_guess < num:
print(“Guess is low”)
elif user_guess > num:
print(“Guess is high”)
else:
print(“You guessed it!”)
Keep running the program until you get one Guess is high, Guess is low, and you guessed it response.

```python
from random import randint
print("micpor9577")
num = randint(1, 9)
user_guess = 0
while user_guess != num:
    user_guess = int(input("Enter a guess from 1 to 9:"))
    if user_guess < num:
        print("Guess is low")
    elif user_guess > num:
        print("Guess is high")
    else:
        print("You guessed it!")
```

### Explanation:

This Python script is a simple number-guessing game. Here's how it works:

1. **Importing Libraries:**
   - The `randint` function is imported from the `random` module. This function is used to generate a random integer within a specified range.

2. **Game Initialization:**
   - The program prints the message "micpor9577".
   - A random number (`num`) between 1 and 9 is generated using `randint(1, 9)`.
   - A variable `user_guess` is initialized to 0 to start the guessing loop.

3. **Game Loop:**
   - The game enters a `while` loop that continues until the user's guess matches the randomly generated number.
   - The user is prompted to enter a guess between 1 and 9.
   - If the guess is lower than the number, the program prints "Guess is low".
   - If the guess is higher than the number, the program prints "Guess is high".
   - If the guess is correct, the program prints "You guessed it!" and the loop exits.

This script provides a simple interactive game that helps users practice their understanding of loops, conditionals, and input handling in Python.
Transcribed Image Text:```python from random import randint print("micpor9577") num = randint(1, 9) user_guess = 0 while user_guess != num: user_guess = int(input("Enter a guess from 1 to 9:")) if user_guess < num: print("Guess is low") elif user_guess > num: print("Guess is high") else: print("You guessed it!") ``` ### Explanation: This Python script is a simple number-guessing game. Here's how it works: 1. **Importing Libraries:** - The `randint` function is imported from the `random` module. This function is used to generate a random integer within a specified range. 2. **Game Initialization:** - The program prints the message "micpor9577". - A random number (`num`) between 1 and 9 is generated using `randint(1, 9)`. - A variable `user_guess` is initialized to 0 to start the guessing loop. 3. **Game Loop:** - The game enters a `while` loop that continues until the user's guess matches the randomly generated number. - The user is prompted to enter a guess between 1 and 9. - If the guess is lower than the number, the program prints "Guess is low". - If the guess is higher than the number, the program prints "Guess is high". - If the guess is correct, the program prints "You guessed it!" and the loop exits. This script provides a simple interactive game that helps users practice their understanding of loops, conditionals, and input handling in Python.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 5 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education