创建一个程序,输入工作小时数和小时费率,并输出工资。注意:每小时超过 40 小时,他们获得 1.5 倍的钱。
错误在第 22 行和第 25 行。我想将答案四舍五入到小数点后 2 位,但它显示“并非所有参数都在字符串格式化期间转换。”
# Constants for hours over 40
BONUS_MONEY_HOURS=40.0
BONUS_MONEY_RATE=1.5
# Inputting the hourly rate and amount of hours worked
hourly_rate=float(input("Please enter how much you make per hour: "))
hours_worked=float(input("Please enter how many hours worked: "))
# Formulas for calculating the amount paid
hours_under_40=float(hourly_rate*hours_worked)
hours_over_40=float(hours_worked-BONUS_MONEY_HOURS)
bonus_money=float(hours_over_40*BONUS_MONEY_RATE)
bonus_plus_normal=float(bonus_money+hours_under_40)
# Outputting the amount paid from different inputs
if hours_worked > 0 and hours_worked < BONUS_MONEY_HOURS:
print "You get paid $.2f"%hours_under_40
elif hours_worked > 0 and hours_worked > BONUS_MONEY_HOURS:
print "You get paid $.2f"%bonus_plus_normal
elif hours_worked < 0:
print "Invalid input. "
elif hourly_rate < 0:
print "Invalid input. "