Untitled

 avatar
unknown
plain_text
2 years ago
522 B
5
Indexable
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)
Editor is loading...