Untitled

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

print("Welcome to the Guessing Game!")

number = random.randint(1, 20)
attempts = 0

while attempts < 5:
    guess = int(input("Guess a number between 1 and 20: "))
    attempts += 1

    if guess == number:
        print("Congratulations! You guessed the number in", attempts, "attempts.")
        break
    elif guess < number:
        print("Your guess is too low.")
    else:
        print("Your guess is too high.")

if attempts == 5:
    print("Sorry, you ran out of attempts. The number was", number)