Код: Выделить всё
import random
number_to_guess = random.randint(1, 10)
while True:
guess = input("Guess a number between 1 and 10: ")
# This crashes if 'guess' is not a number
if int(guess) == number_to_guess:
print("You won!")
break
else:
print("Wrong, try again.")
Если я введу «привет», я получу:
Код: Выделить всё
ValueError: invalid literal for int() with base 10
Подробнее здесь: https://stackoverflow.com/questions/798 ... while-loop
Мобильная версия