top of page
Search

Learn Lua Step-by-Step: GST & Discount Calculator Example

  • Writer: raaj kumar
    raaj kumar
  • Feb 10
  • 2 min read


Published on: 10 Feb 2026Category: Lua Programming / Beginner Tutorial

Introduction

Lua ek lightweight aur beginner-friendly scripting language hai jo gaming, automation, aur mini projects ke liye perfect hai.

Is blog mein hum ek GST + Discount Calculator banayenge, step-by-step, jise aap easily samajh sakte ho aur apne projects me use kar sakte ho.

Step 1: Setting Up Lua

Aap Lua ka code online compiler me run kar sakte ho ya apne PC me Lua install karke practice kar sakte ho.

Test ke liye simple program:

print("Hello, Lua!")

Output:

Hello, Lua!

✅ Agar ye output aa gaya, to Lua setup sahi hai.

Step 2: Basic Price and GST Calculation

Ab hum ek product ka price aur GST calculate karenge.

price = 2045
gst = 0.12

gst_amount = price * gst
net_price = price + gst_amount

print(string.format("Net Price: %.2f", net_price))

Output:

Net Price: 2290.40

💡 Tip: string.format("%.2f") ka use professional bills me hota hai, taki 2 decimal digits dikhaye jaaye.

Step 3: Adding Discount Logic

Agar net price 2000 se zyada ho, to 10% discount apply karenge:

if net_price > 2000 then
    discount = net_price * 0.10
    final_price = net_price - discount
    print(string.format("Discounted Price: %.2f", final_price))
else
    final_price = net_price
    print("No discount!")
end

Output:

Discounted Price: 2061.36

Step 4: Bonus Tips for Beginners

  • Hamesha consistent variable names use karo, jaise net_price aur discount.

  • Lua keywords lowercase me hi likho: if, then, else, end.

  • Professional output ke liye hamesha string.format("%.2f") ka use karo.

  • Code clean aur readable rakho, especially jab blog ya website me post kar rahe ho.

Step 5: Next Steps

Ab aap ye calculator extend kar sakte ho:

  • Multiple items ke liye table use karo

  • Loop chala ke total calculate karo

  • Har item ka GST aur discount apply karo

  • Final report generate karo

Is tarah ka project Tally automation ya gaming inventory management ke liye bhi useful hai.


Lua GST and Discount Calculator code example with price calculation
Lua script calculating GST and discount for a product price, with conditional logic applied based on price thresholds.
Conclusion
  • Lua beginners ke liye simple aur fun language hai.

  • GST + Discount Calculator ek real-world example hai jo aapko coding aur logic dono sikhaata hai.

  • Next step: Tables, Loops, Multiple Items, File I/O.

💡 Pro Tip: Blog ke liye code aur output clearly dikhaye, aur readers ke liye step-by-step headings rakho.

Agar chaho to main Phase 2 blog bhi bana doon jisme:

  • Multiple items in a table

  • GST + Discount per item

  • Final professional bill output


 
 
 

Comments


bottom of page