function prompt_read(prompt)
print(prompt)
return tonumber(io.read())
end
math.randomseed(os.time())
math.random()
num = math.random(1, 100)
tries = 0
print('Угадайте число от 0 до 100.')
repeat
guess = prompt_read("Попытка: ")
if (guess > 100) or (guess < 0) then
print("Неверно!")
elseif guess > num then
print("Нет, нужно меньше!")
elseif guess < num then
print("Нет, нужно больше!")
else
print("Вы угадали!")
end
tries = tries + 1
until num == guess
print(string.format("Вам потребовалось %i попыток!", tries))