Python 用加班时间改写工资计算,并创建一个名为computepay的函数,该函数包含两个参数(小时和费率0
这是我的代码,顺便说一句,我对Stackoverflow和一般编码都是新手,所以请原谅我在格式化此问题时犯了一些错误:Python 用加班时间改写工资计算,并创建一个名为computepay的函数,该函数包含两个参数(小时和费率0,python,function,parameters,Python,Function,Parameters,这是我的代码,顺便说一句,我对Stackoverflow和一般编码都是新手,所以请原谅我在格式化此问题时犯了一些错误: hours = int(input('Enter hours:')) rate = int(input('Enter rate:')) pay =('Your pay this month' + str((hours + hours/2) * rate)) def computepay(hours,rate): pay =('Your pay this month' + st
hours = int(input('Enter hours:'))
rate = int(input('Enter rate:'))
pay =('Your pay this month' + str((hours + hours/2) * rate))
def computepay(hours,rate):
pay =('Your pay this month' + str((hours + hours/2) * rate))
return pay
print(pay)
考虑到加班和正常工资率,您似乎需要知道员工在每个类别中工作的时间。考虑到这一点,这里有一个简化的示例来说明一些关键概念 例如:
def computepay(hours, rate):
return hours * rate
regular_rate = float(input("Hourly rate in dollars: "))
regular_hours = float(input("Regular hours worked: "))
overtime_hours = float(input("Overtime hours worked: "))
regular_pay = computepay(regular_hours, regular_rate)
overtime_pay = computepay(overtime_hours, regular_rate * 1.5)
total_pay = regular_pay + overtime_pay
print(f"This pay period you earned: ${total_pay:.2f}")
输出:
Hourly rate in dollars: 15.00
Regular hours worked: 40
Overtime hours worked: 10
This pay period you earned: $825.00
1前3行是否试图在没有函数的情况下计算工资,下面几行是否试图将这些行转换为函数?2是否应该有不同的加班费率,3在正常工资多少小时后,您开始获得加班费率?函数中的4行应该从函数声明行缩进。