Code: Select all
import random
# - Write a program where the computer picks a random number between 1 and 100.
# - The user has to guess the number, with the program providing hints ("too high" or "too low").
# - Use loops to allow multiple guesses and conditionals to check user inputs.
# - Bonus: Add a scoring system based on the number of guesses.
def guess_game():
get_guess = random.randint(1,100)
guesses = 0
while True:
guess = input("Guess number: ")
guess = int(guess)
guesses += 1
if guesses == 3:
print(f"You are out of guesses! The number is {get_guess}")
break
if guess < get_guess:
print("Too low")
elif guess > get_guess:
print("Too high")
elif guess == get_guess:
print(f"yes {guess} is the correct number!")
break
guess_game()