Advertisement
kkDav1337

Math Operations with Function

Jun 28th, 2020
14,462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.47 KB | None | 0 0
  1. local operation = {
  2.     ["+"] = function(x,y) return x+y end,
  3.     ["-"] = function(x,y) return x-y end,
  4.     ["*"] = function(x,y) return x*y end,
  5.     ["/"] = function(x,y) return x/y end
  6. }
  7.  
  8. local function default()
  9.     print("No opreation has been selected")
  10. end
  11.  
  12. print("Choose your first number:")
  13. local num1 = io.read()
  14. print("Choose your second number:")
  15. local num2 = io.read()
  16. print("Choose your operation:")
  17. local func = operation[io.read()] or default
  18. print(func(num1,num2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement