У меня есть мини игра, где программа загадывает число, а пользователь отгадывает его:
import time
import random
rand_number = random.randint(1, 20)
correct_guess = rand_number
attempts = int(1)
out_of_attempts = 6
win = False
print("""I am thinking of a 1-20 number.
You have 5 attempts. If you didn`t guessed correctly - you lose.
If you give up - input 25
Input 0 to leave.""")
while attempts < out_of_attempts:
your_guess = int(input("Your {} guess: ".format(attempts)))
if your_guess == correct_guess:
time.sleep(0.3)
print("Correct!")
win = True
break
if your_guess == 0:
print("Leaving now...")
break
try:
if your_guess == 25:
print("Ha-Ha, I won! Correct number was {}".format (rand_number))
if your_guess == ""
print("Dont input empty guess.")
elif your_guess > 20:
print("Only numbers from 1 to 20.")
else:
time.sleep(0.5)
print("Wrong!")
attempts += 1
except ValueError:
print("Only numbers, not literal.")
if not win:
print("You are out of attempts. Correct number was {}.".format(rand_number))
Попадается исключение: ValueError: invalid literal for int() with base 10: ''
Но я же написал действия при пустом вводе и такой ошибке, откуда она?