# Function to calculate salary
def calculate_salary(hourly_rate, hours_worked, overtime_hours=0, overtime_rate_multiplier=1.5, deductions=0):
# Regular hours are 40 hours, overtime is anything beyond that
regular_hours = min(hours_worked, 40)
overtime_hours = max(0, hours_worked - 40)
# Regular pay
regular_pay = regular_hours * hourly_rate
# Overtime pay
overtime_pay = overtime_hours * hourly_rate * overtime_rate_multiplier
# Total earnings
total_earnings = regular_pay + overtime_pay
# Subtract deductions
net_salary = total_earnings - deductions
return {
'Regular Pay': regular_pay,
'Overtime Pay': overtime_pay,
'Total Earnings': total_earnings,
'Deductions': deductions,
'Net Salary': net_salary
}
# Example usage
hourly_rate = 20 # Example hourly rate in dollars
hours_worked = 45 # Example hours worked in a week
overtime_hours = 5 # Example overtime hours
deductions = 50 # Example deductions (e.g., taxes, insurance)
salary_details = calculate_salary(hourly_rate, hours_worked, overtime_hours, deductions=deductions)
for key, value in salary_details.items():
print(f"{key}: ${value:.2f}")