Answer to Question #306709 in Python for Christine

Question #306709

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-07T12:54:33-0500



import random
print ("welcome to the guess my number ")


print ("you have 5 guesses\n")





the_number = random.randint(1, 100)


user = int(input("Guess the number?"))


count = 1
while user != the_number:


    if user > the_number:
     print ("Lower")


    elif user < the_number:
     print ("Higher")


    else :
     print ("congratulations")


    user = int(input("What's the number?"))
    count += 1
    if count == 5:
     break




print(" the number is", the_number)


input ("\nPress enter to exit")    

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