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.
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')
Comments
Leave a comment