Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
581 B
0
Indexable
Never
import random

def guess_the_number():
    print("Welcome to the Guess the Number game!")
    secret_number = random.randint(1, 100)
    attempts = 0

    while True:
        guess = int(input("Enter your guess (between 1 and 100): "))
        attempts += 1

        if guess == secret_number:
            print(f"Congratulations! You guessed the number in {attempts} attempts.")
            break
        elif guess < secret_number:
            print("Too low! Try again.")
        else:
            print("Too high! Try again.")

if __name__ == "__main__":
    guess_the_number()
Leave a Comment