CodeNewbie Community 🌱

thomlevi
thomlevi

Posted on

Started Small: Building a Gratuity Calculator to Learn Coding Basics

Hey everyone!

I recently started exploring small projects to improve my coding basics and ended up creating a simple UAE Gratuity Calculator!

The goal was to build something practical while learning logic, user input handling, and basic backend structure. The calculator estimates end-of-service gratuity based on UAE labor rules taking in salary, years of service, and contract type.

Here’s a small part of the logic I used in Python

def calculate_gratuity(salary, years, contract_type):
if contract_type.lower() == "limited":
gratuity = salary * 21/30 * years # 21 days per year
else:
gratuity = salary * 30/30 * years # 30 days per year (for unlimited)
return round(gratuity, 2)

Example:

basic_salary = 5000
years_worked = 3
contract = "limited"

result = calculate_gratuity(basic_salary, years_worked, contract)
print(f"Estimated Gratuity: AED {result}")

It was amazing to see how just a few lines of code could replicate a real HR function. I also learned how to test and improve input validation to prevent calculation errors.

Now I’m curious what kind of small tools or calculators have you built while learning? Would love to see other beginner projects like this!

Top comments (0)