所以我做了一个指数计算器,我添加了一个功能,如果数字太大而无法计算,它只会告诉你它有多少位数。这是我的代码:
io.write("Number is to big,calculate only number of digits instead? (Y/N): ")
local ans = io.read()
if ans:lower() == "y" then
--Irrelevant code (Doesnt get executed)
elseif ans:lower() == "n" then
--Irrelevant code
else
print("Error")
os.exit()
end
它总是会打印“错误”并结束程序,有什么帮助吗?
规范:并不是说我输入什么无关紧要,而是我什至不让我输入,io.read() 不执行并且打印错误(注意:这不会打开文件或其他内容)
第二个规范:它在我什至无法输入内容之前打印错误,我什至无法按 Enter,并且在我的代码中,在该代码段之前我多次调用 io.read 并且它工作正常