简体   繁体   English

为包括加班费的工资计算器编写学校项目。 无法弄清楚我在这方面做错了什么

[英]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.

相关问题 我正在尝试使用模块 simplegui 在 CodeSkulptor 中制作一个带有两个输入字段的计算器。 我不知道我做错了什么 - I'm trying to make a calculator with two input fields in CodeSkulptor using the module simplegui. I can't figure out what I am doing wrong python/tkinter 新手,不知道我做错了什么? - New to python/tkinter and can't figure out what I'm doing wrong? 我不知道这个房间计算器 - I can't figure out this room calculator 我试图了解类和函数,但似乎无法弄清楚我的代码出了什么问题 - I am trying to understand class and function and can't seem to figure out what is wrong with my code 我不知道这个素数检查器有什么问题 - I can't figure out what is wrong with this prime checker 在计算器上工作,但我不知道如何添加 pi - Working on a calculator but I can't figure out how to add pi 写这个 function 时我做错了什么? - What am I doing wrong when writing this function? 我正在尝试使用记事本++启动一个简单的计算器程序,我做错了什么? - I am trying to start a simple calculator program using notepad++, what am I doing wrong? 这个自定义计算器的Python代码现在可以正常工作了,我把它弄坏了,无法弄清楚哪里出了问题 - This Python code for a Custom Calculator was working now I broke it and I can't figure out where I went wrong 我试图找出 .csv 文件的最大值和最小值,但我无法弄清楚我做错了什么 - Im trying to figure out the max and min of a .csv file and i cant figure out what im doing wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM