import random
# Generate a random number between 1 and 100
secret_number = random.randint(1, 100)
# Number of attempts
attempts = 0
print("Welcome to the Number Guessing Game!")
while True:
# Get user input
guess = int(input("Enter your guess (1-100): "))
# Increase the number of attempts
attempts += 1
# Check if the guess is correct
if guess == secret_number:
print("Congratulations! You guessed the number in", attempts, "attempts.")
break
elif guess < secret_number:
print("Too low! Try again.")
else:
print("Too high! Try again.")