将python转换为lua

发布于 2025-02-07 22:23:47 字数 961 浏览 3 评论 0原文

我必须将这个python&nbsp“我进行了一段时间的程序转换为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

I have to convert this Python program I made a while ago into a Lua program. I've done some of it, I just can't seem to format my list correctly or take the data entered by the user and pass it through my if-else statements.

The program is supposed to get the age of the user as well as the day of the week and then output their airfare. If their age is 65 or older and it's the second day of the week, the price is $75 otherwise it is $150.

Any help would be appreciated

Thanks!

Python Code

1

Lua code

2

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃兔兔 2025-02-14 22:23:47
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
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
胡大本事 2025-02-14 22:23:47

检查这个项目,我是作者,P​​oroject还活着,所以请报告任何我的错误,并尽快解决,建议新的A功能,如果可能的话,我也会仔细研究它:
https://github.com/mhadhbixissam/pythoniclua

check this project , i am the author , the poroject is alive so please report any i bug and i fixed as soon as possible , suggest a new a feature also i will look about it if it is possible i add it :
https://github.com/MhadhbiXissam/pythonicLua

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文