Session 18

Source Code

local myName = ""
print("Name: " .. myName)

-- define main function
function main()
    print("Hello Main Function")
    print(myName)
    local choice = nil
    print("Menu")
    print("E1 - Example 1")
    print("Q - Quit")
    io.write("Choice: ")
    choice = io.read()
    if choice == "E1" then
        -- Example 1 Function call
        example1()

    elseif choice == "E2" then
        -- Example 2 Function call
        example2()

    elseif choice == "E3" then
        -- Example 3 Function call
        example3()

    elseif choice == "E4" then
        -- Example 4 Function call
        example4()

    elseif choice == "Q" then
        done = true
    else
        print("Invalid Choice")
    end
end

-- define Example 1 Function
function example1()
    print("Example 1")
    -- define friends list
    

    -- print the number of elements
   

    -- print the element one by one
    

    -- using a for loop, print the index and elements
    

    -- assign value to first friend
    

    -- assign value to the last friend
    

    -- print the friends
    

end

-- define Example 2 Function
function example2()
    -- create an empty list
    

    -- add an element to the end of the list (append)
    

    -- add an element to the end of the list (append)
    

    -- add an element to the beginning of the list (insert)
    

    -- print using for in loop
    

    -- print using for in loop with index
    

    -- delete a fruit
    

    -- print using for in loop
    

end

-- define Example 3 Function
function example3()
    
end

-- define Example 4 Function
function example4()
    
end

-- call to main function, do not delete!
main()

s18problem1.lua

s18problem2.lua

s18problem3.lua

s18problem4.lua

s18problem5.lua

s18problem6.lua

s18problem7.lua

s18problem8.lua

s18problem9.lua

playlist.lua

Last updated

Was this helpful?