# Guess a number from 1 to 10 # Write the statements requested in Steps 1-6 below  # See the examples in the provided code # Use structured programming and indent your code. # Programmer Name: *****add your name here**** import random # uses randrange instead of randint for better results in Python 3.7 # randrange stops just before the upper range, use (1, 11) for 1-10 num = random.randrange(1, 11) # Step 1: Ask the player to enter a name or quit to exit # Step 2: use a while statement to test when the name is not equal to quit # Step 3: input enter a number from 1 to 10 for the variable your_guess # display the number guessed print("Your number is", your_guess) while num != your_guess: # Step 4: Write an if statement for your_guess is less than num print("Your guess is too low.") your_guess = int(input("Guess another number from 1 to 10: ")) elif your_guess > num: print("Your guess is too high") your_guess = int(input("Guess another number from 1 to 10: ")) else: break print("The correct number was", num) # Step 5 display text with your guess and You won, name print("***************************************************************") # Step 6 ask the player to enter a name or quit to exit num = random.randrange(1, 11) print("Thank you for playing!")

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

# Guess a number from 1 to 10

# Write the statements requested in Steps 1-6 below 

# See the examples in the provided code

# Use structured programming and indent your code.

# Programmer Name: *****add your name here**** import random

# uses randrange instead of randint for better results in Python 3.7

# randrange stops just before the upper range, use (1, 11) for 1-10 num = random.randrange(1, 11)

# Step 1: Ask the player to enter a name or quit to exit

# Step 2: use a while statement to test when the name is not equal to quit

# Step 3: input enter a number from 1 to 10 for the variable your_guess

# display the number guessed print("Your number is", your_guess) while num != your_guess:

# Step 4: Write an if statement for your_guess is less than num print("Your guess is too low.")

your_guess = int(input("Guess another number from 1 to 10: "))

elif your_guess > num: print("Your guess is too high")

your_guess = int(input("Guess another number from 1 to 10: "))

else: break print("The correct number was", num)

# Step 5 display text with your guess and You won, name print("***************************************************************")

# Step 6 ask the player to enter a name or quit to exit num = random.randrange(1, 11)

print("Thank you for playing!")

Expert Solution
Step 1

#guess a number from 1 to 10
#by C. calongne, 01/14/2019
#Pseudocode & python with Iteration M3Lab1_student.py
#guess a number from 1 to 10
#write the statements requested in step 1-6 below
#
#see the examples in provided code
#use structured programming and indent your code
#Programmer name ******add your name here********

import random
#uses randrange instead of randint for better results in python 3.7
#rand range stops just before the upper range, use (1, 11) for 1-10

num = random.randrange(1, 11)
#step1: Ask the player to enter a name or quit to exit
name = input("enter your name or quit to exit:\t")

#Step2: Use a while statement to test when the name is not equal to quit
while(name != "quit"):
    #step3: input a number from 1 to 10 for the variable your_guess
    your_guess = int(input("guess a number from 1 to 10:\t"))
    #display the number guessed
    print("Your number is :\t",your_guess)
    while(num != your_guess):
        #write an if statement for your_guess is less than num
        if(your_guess < num):
            print("Your guess is too low")
            your_guess = int(input("guess another number from 1 to 10:\t"))
        elif(your_guess > num):
            print("your guess is too high")
            your_guess = int(input("guess another number from 1 to 10:\t"))
        else:
            break
    print("The correct name was:\t",num)
    #step5: Display text with your guess and you won, name
    print("Your guess was :\t",your_guess, "You won ",name)
    print("**********************************************************")
    #step6: ask the player to enter a name or exit
    name = input("enter your name or quit to exit:\t")
print("Thank You")
    
   Activities
Text Editor
Sun 11:18
guessing game.py
-/Desktop
Save
= 60
Open A
#guess a number Trom 1 to 10
#write the statemen

 

 

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Mathematical functions
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