Untitled
Anonymous
plain_text
04/13/2023 5:29 PM
696 B
17
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...