计算工资总额的Python程序
总工资是员工在任何扣除之前的特定时间段内赚取的金额。根据员工的薪酬方式,有许多不同的方法可以计算总薪酬。本文介绍了两种最常见的方式 - 时薪和薪水。
时薪雇员
如果雇员按小时支付工资,则他每工作一小时就获得固定数额的报酬。因此,如果他每小时获得 100 卢比的报酬,并且他工作 8 小时,那么他的总工资为 800 卢比。小时工的总工资必须根据 由于一项称为加班的规则,联邦政府的《公平劳工标准法》规定每周工作时间超过 40 小时的雇员必须以不低于正常工资率的 1.5 倍的比率获得加班费。
例子:
Let’s assume A works as an hourly paid employee, and he is paid 100/hour.
If he worked for 50 hours in a week then he will get the overtime pay for the extra hours he worked i.e. he will be paid 1.5 times of Rs.100 for 10 hours (50-40).
if worked_hours > 40 then:
total gross pay = (hourly_wage *40) + (1.5 * hourly_wage * (worked_hours-40)).
if worked_hours < 40 then:
total gross pay = hourly_wage *worked_hours.
ramu’s worked_hours=50 i.e. greater than 40 hours.
total gross pay = 100*40 + (1.5)*100*10 => Rs.5,500.
程序:
Python3
def weeklyPaid(hours_worked, wage):
if hours_worked > 40:
return 40 * wage + (hours_worked - 40) * wage * 1.5
else:
return hours_worked * wage
hours_worked = 50
wage = 100
pay = weeklyPaid(hours_worked, wage)
print(f"Total gross pay: Rs.{pay:.2f} ")
Python3
def getGrossPay(annual_salary, no_of_pay_peroids):
return float(annual_salary/no_of_pay_peroids)
# driver code
# annual_salary in lakhs
annual_salary = 12
no_of_pay_peroids = 12
pay = getGrossPay(annual_salary, no_of_pay_peroids)
print(f"Total gross pay: Rs.{pay:.2f} lakhs ")
输出:
Total gross pay: Rs.5500.00
受薪雇员
薪水通常每年报价,但通常,员工每月支付一次。要计算受薪雇员的总薪酬,我们需要将年薪除以一年中的支付期数(即他们在一年中分期付款的次数)。
例子:
Let’s assume B works as a salaried employee, and he is paid 12 lakhs per annum.
If B was paid monthly then the gross payment will be 12 lakhs / 12.
gross pay= 12/12 => 1 lakh.
程序:
蟒蛇3
def getGrossPay(annual_salary, no_of_pay_peroids):
return float(annual_salary/no_of_pay_peroids)
# driver code
# annual_salary in lakhs
annual_salary = 12
no_of_pay_peroids = 12
pay = getGrossPay(annual_salary, no_of_pay_peroids)
print(f"Total gross pay: Rs.{pay:.2f} lakhs ")
输出:
Total gross pay: Rs.1.00 lakhs
时间复杂度: O (1)