Input 如何使用io.read读取数字
我是Lua初学者,不知道如何正确使用Input 如何使用io.read读取数字,input,lua,Input,Lua,我是Lua初学者,不知道如何正确使用io。阅读等等。 我正在做一件非常简单的事情,我想将age=18语句替换为可以从用户那里获得输入的内容,让他们说出自己的年龄 与此相反: age = 18 if age >= 18 and age <=80 then print("You may enter!") else print("You are not allowed in, sorry!") end 年龄=18岁 如果年龄>=18且年龄=18且年龄,则可以尝试使用将变
io。阅读等等。
我正在做一件非常简单的事情,我想将age=18
语句替换为可以从用户那里获得输入的内容,让他们说出自己的年龄
与此相反:
age = 18
if age >= 18 and age <=80 then
print("You may enter!")
else
print("You are not allowed in, sorry!")
end
年龄=18岁
如果年龄>=18且年龄=18且年龄,则可以尝试使用将变量转换为数字,然后检查该变量的布尔值
print("What's your age?")
local age = tonumber(io.read())
if age and age >= 18 and age <= 80 then
print("You may enter!")
else
print("You are not allowed in, sorry!")
end
print(“您的年龄是多少?”)
本地年龄=tonumber(io.read())
如果年龄和年龄>=18且年龄,Lua解释器将为您打开。您可以使用io.read
读取数字,并且如所述,您可以使用n
格式指示您要读取整数或浮点
local age = io.stdin:read 'n'
if age then
-- age is a number
else
-- age is nil
end
local age = io.stdin:read 'n'
if age then
-- age is a number
else
-- age is nil
end