Answer to Question #306471 in Python for Christine

Question #306471

Machine Problem 1


Number Guessing Game


In the number guessing game, the computer will randomly select a number from a range of numbers e.g. 1-100 and then the game will give the player five attempts to guess the number.


Gameplay:


• If the player's guess is higher than the chosen number, the program will tell the player to try another LOWER than the previous guess.


• If the player's guess is lower than the chosen number, the program will tell the player to try another number HIGHER than the previous guess.


■ If the player guesses the number before he consumes the five attempts, then display congratulatory message.



1
Expert's answer
2022-03-05T13:55:05-0500
import random
choice = random.choice(range(1,101))
for i in range(5):
    input1 = int(input('Enter your guess here: '))
    if input1 > choice:
        print('Try value lower than previous guess')
    elif input1 < choice:
        print('Try value higher than previous guess)
    else:
        print('Congratulations, you are correct')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS