Answered step by step
Verified Expert Solution
Question
1 Approved Answer
If i add the first line as suggested, i get the below error lua: main.lua: 1 : attempt to index global ' op ' (
If i add the first line as suggested, i get the below error
lua: main.lua:: attempt to index global opa nil value
stack traceback:
main.lua:: in main chunk
C:
i also see these in my commentsdialog box on runtime
Program output
lua: main.lua:: bad argument # to 'tonumber' base out of range
stack traceback:
C: in function 'tonumber'
main.lua:: in main chunk
C:
Enter command:
so i have commented it out inorder to compile the program, however i am still not geting the correct program output.
just for reference, this is the grid which i am assuming is part of grid.txt the i am assuming is being omitted but i just used it as a point of reference for you
For numbering purposes the rows and values are indexed on a index basis ie the
first row is row and the first column is column
can i please ask that you check the outputs before responding back, as this is the th iteration of the same question that i have been asking for assistance on i am really appreciative of your help and guidance but i feel we are stuck on question and without meus getting it correct, i am not sure how to even attempt the more complez questions being asked. i hope you can understand where i am coming from by requesting this and if possible you run the code in a compiler.
local file opopenfilename r
function loadgridfilename
local file ioopengridtxtr
if not file then
printError: unable to open file"
return
end
local grid
for line in file:lines do
local row
for num in line:gmatchd do
table.insertrow tonumbernum
end
table.insertgrid row
end
file:close
return grid
end
function areneighbourscity city grid
if city and city #grid and city and city #gridcity then
return gridcitycity
else
return false
end
end
local grid loadgridgridtxt
while true do
iowriteEnter command:
local command ioread:lower Convert to lowercase for caseinsensitivity
if command "areneighbours" then
local city city tonumberioreadn tonumberioreadn
if city and city then
printareneighbourscity city grid
else
print Invalid input for cities. Please enter valid numbers"
end
elseif command "exit" then
break
else
printUnknown command"
end
end
Enter command: areni eighbours
false
Enter command: Unknown command
Enter command: areneighbours
false
Enter command: Unknown command
Enter command:
THE EXPECTED RESULTS SHOULD BE AS below
Expected output on test data with input : Yes
Expected output on test data with input : No
Expected output on test data with input : Yes
Expected output on test data with input : Yes
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started