我必须把我刚才做的这个Python程序转换成一个Lua程序。我已经做了一些,我只是不能正确地格式化我的列表,或者把用户输入的数据传递给我的if-else语句。
该程序应该得到用户的年龄以及一周中的一天,然后输出他们的机票。如果他们的年龄在65岁或以上,这是一周的第二天,价格是75美元,否则是150美元。
如能提供任何帮助,将不胜感激。
谢谢!
Python代码
Lua码
week_day = {'Monday = 1', 'Tuesday = 2', 'Wednesday = 3', 'Thursday = 4','Friday = 5', 'Saturday = 6', 'Sunday = 7'}
print("Enter your age:")
local ans = io.read()
print("Enter the day of the week (1-7):")
local wkd = io.read()
if (ans >= 65) and (wkd == 2) then
print("Your fair is $75", "\n")
else
print("Your fair is $150", "\n")
end
发布于 2022-06-15 22:57:40
io.write("Enter your age: ") -- use io.write, to print text, without a newline, so you can type on the same line
local ans = tonumber(io.read()) -- io.read returns a string, you need to convert it with tonumber
io.write("Enter the day of the week (1-7): ")
local wkd = tonumber(io.read())
if (ans >= 65) and (wkd == 2) then
print("Your fair is $75", "\n") -- \n is not really nessesary as print creates a new line after
else
print("Your fair is $150", "\n")
end
https://stackoverflow.com/questions/72638567
复制相似问题