Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
508 B
0
Indexable
Never
import random

print("Welcome to Guess the Number!")
print("I'm thinking of a number between 1 and 100.")

secret_number = random.randint(1, 100)
guess = None
num_guesses = 0

while guess != secret_number:
    guess = int(input("Guess the number: "))
    num_guesses += 1

    if guess < secret_number:
        print("Too low! Guess again.")
    elif guess > secret_number:
        print("Too high! Guess again.")
    else:
        print(f"Congratulations! You guessed the number in {num_guesses} guesses.")