Answer to Question #306735 in Python for Dhea M. Maddela

Question #306735

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.


I need the code to have an output stated above.


1
Expert's answer
2022-03-06T04:49:46-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