Untitled

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

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

    while True:
        guess = input("Enter your guess (between 1 and 100): ")
        try:
            guess = int(guess)
            attempts += 1
            if guess < secret_number:
                print("Too low! Try again.")
            elif guess > secret_number:
                print("Too high! Try again.")
            else:
                print(f"Congratulations! You've guessed the number {secret_number} in {attempts} attempts!")
                break
        except ValueError:
            print("Please enter a valid number.")

if __name__ == "__main__":
    main()