我怎么把所有的工资加起来?



我如何在我的代码中添加所有的报酬?

for i in range (n):

if hrs[i] >=0 and hrs[i]<=40:
pay = (h[i] * 9.5)


elif hrs[i] >40 and hrs[i]<=59:
pay = 380 +(h[i] - 40) * 9.5 * 1.5

else :
hrs[i] >60
pay = 665 + (h[i] - 60) * 9.5 * 2.0


print ('{:3d}        {:15s}{:3d}      {}   '.format (i+1,name[i],hrs[i],pay,))

应该可以:

total = 0
for i in range(20):
pay = 0
if hrs[i] >=0 and hrs[i]<=40:
pay += (h[i] * 9.5)
elif hrs[i] >40 and hrs[i]<=59:
pay += 380 +(h[i] - 40) * 9.5 * 1.5
else :
pay += 665 + (h[i] - 60) * 9.5 * 2.0
total += pay
print ('{:3d}        {:15s}{:3d}      {}   '.format (i+1,name[i],hrs[i],pay,))

hrs[i] >60行是不必要的,因为它不做任何事情,所以我建议删除它!

相关内容

  • 没有找到相关文章

最新更新