import random
def guess_the_number():
secret_number = random.randint(1, 100)
attempts = 0
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 100.")
while True:
user_guess = int(input("Take a guess: "))
attempts += 1
if user_guess < secret_number:
print("Too low! Try again.")
elif user_guess > secret_number:
print("Too high! Try again.")
else:
print(f"Congrats! You've guessed the number {secret_number} in {attempts} tries.")
break
guess_the_number()
Welcome to the Number Guessing Game!
I'm thinking of a number between 1 and 100.
Too low! Try again.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[3], line 22
19 print(f"Congrats! You've guessed the number {secret_number} in {attempts} tries.")
20 break
---> 22 guess_the_number()
Cell In[3], line 11, in guess_the_number()
8 print("I'm thinking of a number between 1 and 100.")
10 while True:
---> 11 user_guess = int(input("Take a guess: "))
12 attempts += 1
14 if user_guess < secret_number:
ValueError: invalid literal for int() with base 10: ''