Untitled
unknown
plain_text
2 years ago
580 B
8
Indexable
import random
# Generate a random number between 1 and 100
number = random.randint(1, 100)
print("Welcome to the Guessing Game!")
print("I'm thinking of a number between 1 and 100. Try to guess it!")
# Set the initial number of attempts
attempts = 0
# Game loop
while True:
    guess = int(input("Enter your guess: "))
    attempts += 1
    if guess < number:
        print("Too low, try again!")
    elif guess > number:
        print("Too high, try again!")
    else:
        print(f"Congratulations! You guessed the number {number} in {attempts} attempts!")
        break
Editor is loading...