Untitled
unknown
python
2 years ago
643 B
7
Indexable
import random
def guess_number():
secret_number = random.randint(1, 10)
attempts = 3
print("Welcome to the Guessing Game!")
print("I have chosen a number between 1 and 10. You have 3 attempts to guess it.")
while attempts > 0:
guess = int(input("Enter your guess: "))
if guess == secret_number:
print("Congratulations! You've guessed the correct number!")
break
else:
print("Incorrect guess. Try again.")
attempts -= 1
if attempts == 0:
print("Sorry, you've run out of attempts. The correct number was:", secret_number)
guess_number()Editor is loading...
Leave a Comment