• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Convert Python to Lua

Resolved: Convert Python to Lua

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

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

Answer:

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

If you have better answer, please add a comment about this, thank you!

encoding helper lua python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Shopware 400 Status Error “This value is too long. It should have 255 character or less.” When I Try Updating Database Table

01/04/2023

Resolved: Using AWK to count multiple patterns in a file

01/04/2023

Resolved: significance letter above bar graphic in wrong order

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.