📘 Level: Beginner
🧠 You will learn:
use variables
read user input
work with numbers
apply conditions (if, elseif, else)

🚀 What we will do
In this task, you will create simple calculator, which can add, subtract, multiply and divide two numbers. Everything will happen in the terminal — as in classic console utilities.
🔧 Preparation
You can write code directly in the browser, for example here:
👉 https://replit.com/languages/lua
🧱 Step 1: Get input
We will ask the user to enter two numbers and an operation sign:
print("Enter the first number:")
local a = io.read("*n")
print("Enter the second number:")
local b = io.read("*n")
print("Enter operation (+, -, *, /):")
local op = io.read()🧮 Step 2: Perform the operation
Now we process the input and calculate the result:
if op == "+" then
print("Result: " .. (a + b))
elseif op == "-" then
print("Result: " .. (a - b))
elseif op == "*" then
print("Result: " .. (a * b))
elseif op == "/" then
if b ~= 0 then
print("Result: " .. (a / b))
else
print("You can't divide by zero!")
end
else
print("Unknown operation")
end✅ Verification
Test the calculator:
10, 5, + →
1510, 0, / → warning about division by zero
💡 Additional ideas
Add a restart of the calculator after completion
Make a simple menu before you start
Support fractional numbers
🐾 What's next
Now you have your first console utility on Lua! This is a great base for the next step — creating mini-applications or even simple games.
Join our community and learn to program in a cozy atmosphere!
Code 🐾 is our fluffy assistant who helps beginners learn programming easily and with a smile. Together with him, you can take courses in Lua, Python and other languages, creating real projects step by step.
