Coursework · Stop 1 of 10
Salary calculator
A console program that works out the gross and net pay of a month from the hourly wage.

Goal
Write a program that calculates something useful, with input, conditions and loops.
Implementation
- Grew over three versions: from a plain calculator to asking for working hours, working days, year and month.
- The program counts the working days of the chosen month itself with the calendar module.
- Simplified deductions: payroll tax in steps, church tax depending on the state and social insurance with contribution ceilings.
- Wrong input is caught and asked for again.
Code
From gross to net in a few lines
def payroll_tax(monthly):
if monthly < 1000:
payroll_tax = 5
elif 1000 <= monthly < 2000:
payroll_tax = 15
elif 2000 <= monthly < 3500:
payroll_tax = 25
elif 3500 <= monthly < 5000:
payroll_tax = 35
elif 5000 <= monthly < 7000:
payroll_tax = 42
else:
payroll_tax = 45
netto = monthly * (1 - payroll_tax / 100)
return netto
netto = payroll_tax(monthly)
churchtax_netto = (monthly - netto) * churchtax
pension_insurance_limit = 7550
health_insurance_limit = 5175
if monthly < pension_insurance_limit:
pension_insurance = monthly * .093
unemployment_insurance = monthly * .013
else:
pension_insurance = pension_insurance_limit * .093
unemployment_insurance = pension_insurance_limit * .013
if monthly < health_insurance_limit:
health_insurance = monthly * .073
nursingcare_insurance = monthly * .023
else:
health_insurance = health_insurance_limit * .073
nursingcare_insurance = health_insurance_limit * .023One function picks the tax rate by steps; social insurance is capped at the contribution ceiling.
What I learned
Never trust input. And a program grows better in small versions than in one big go.