[英]Writing a school project for a pay calculator that includes overtime. Can't figure out what I am doing wrong on this
Having issues with getting my program to equal what it is supposed to?在让我的程序达到预期目标时遇到问题? It's supposed to come out to 498.75.它应该是 498.75。 The inputs are supposed to be 45 in the hrs and rate is supposed to be 10.50.输入应该是 45 小时,速率应该是 10.50。 Can someone help me and see if you can catch my error, because I am having problems with it tonight?有人能帮我看看你能不能发现我的错误,因为我今晚遇到了问题?
hrs = input("Enter Hours:")
h = float(hrs)
rate = float(input("Enter Rate:"))
overtime = float(1.5 * rate)
r = float(rate)
pay = h * r
print(float(pay))
print(hrs)
print(rate)
if h > 40:
final = overtime * pay
final_2 = final + pay
if h < 40:
print(pay)
This solution is inspired from the comment of Freek:此解决方案的灵感来自 Freek 的评论:
code:代码:
hrs = float(input("Enter Hours:"))
rate = float(input("Enter Rate:"))
hrs_overtime=max(hrs - 40, 0)
pay = rate * hrs + 0.5 * rate * hrs_overtime
print(pay)
input:输入:
Enter Hours:45
Enter Rate:10.5
output:输出:
498.75
Should separate the overtime hours加班时间应该分开
hrs = float(input("Enter Hours:"))
rate = float(input("Enter Rate:"))
overtime_rate = 1.5 * rate
normal_hrs = 40
if hrs > normal_hrs:
overtime_hrs = hrs - normal_hrs
pay = normal_hrs * rate + overtime_hrs * overtime_rate
else:
pay = hrs * rate
print(hrs, rate)
print(pay)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.