【发布时间】:2021-12-13 00:06:23
【问题描述】:
我正在尝试创建一个需要两个 prmtrs 的函数,num_of_employees 和 hrly_rate。
该列表应包含每个员工的工作小时数和工资。列表的大小应与员工人数相同。它提示用户输入每个员工的工作小时数,计算工资,并创建一个小时数列表和将其添加到列表中的工资。
如果人数少于 40,则按标准支付:工作小时数 * 时薪 如果数字大于 40,则工资为 40 小时以上的小时费率为 1.5。
代码应该显示这个输出: #假设员工人数只有2人,:
insert the number of worked hours: 60
insert the number of worked hours:20
the employee worked for 60 hours and the earned is 700.00$
the employee worked for 20 hours and the earned is 200.00$
但这是我的代码:
def calculate_total_pay_cad(num_employees, hrly_rate_CAD):
rng = range(0, num_employees)
for n in rng:
num_hrs_worked = int(input(('Input the number of worked hours: ')))
if num_hrs_worked < 40:
pay = num_hrs_worked * hrly_rate_CAD
if num_hrs_worked > 40:
pay = num_hrs_worked * (hrly_rate_CAD * 1.5)
for n in rng:
print(f"the employee worked for {num_hrs_worked} and has earned {pay}")
num_employees = int(input(('enter number employees')))
hrly_rate_CAD = int(input(('enter hourly rate: ')))
calculate_total_pay_cad(num_employees,hrly_rate_CAD)
这是我的输出:
Input the number of worked hours: 50
Input the number of worked hours: 20
the employee worked for 20 and has earned 300
the employee worked for 20 and has earned 300
总结 = 我的代码仅输出我的输入列表中的最后一个插入。我如何让它伴随正确的小时数并为每条线路计算工资?
非常感谢。
【问题讨论】:
标签: python for-loop input integer range