English 中文(简体)
2. 支付加班费和半薪,并设立一个称为补薪的职能,其参数为:小时和薪率0。
原标题:Rewrite a pay computation with time-and-a-half for overtime and create a function called computepay which takes two parameters(hours and rate0

这里是我的法典(如果我在编排该问题时犯了某些错误的话,那么,我是新到的,一般如此宽恕我:

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
问题回答

我的教师告诉我,用一种功能解决该问题:computer Pay

def computepay(hours, rate):
if hours > 40:
    reg = rate * hours
    otp = (hours - 40.0) * (rate * 0.5)
    pay = reg + otp
else:
    pay = hours * rate 
return pay

然后,投入部分

sh = input("enter Hours:")
sr = input(" Enter rate:")
fh = float(sh)
fr = float(sr)
xp = computepay(fh,fr)
print("Pay:",xp)
def computepay(hours, rate) :
   return hours * rate
def invalid_input() :
   print("Input Numeric Value")
while True :
   try :
      regular_rate = float(input("Hourly rate in dollars: "))
      break
   except :
      invalid_input()
      continue
while True :
   try :
      regular_hours = float(input("Regular Hours Worked: "))
      break
   except :
      invalid_input()
      continue
while True :
   try :
      overtime_hours = float(input("Overtime hours worked :"))
      break
   except :
      invalid_input()
      continue
overtime_rate = regular_rate * 1.5

regular_pay = computepay(regular_hours, regular_rate)
overtime_pay = computepay(overtime_hours, overtime_rate)
total_pay = regular_pay + overtime_pay

print("PAY : ", total_pay)
def computepay(hours, rate):
    if (hours <= 40.0):
        pay = hours * rate
    else:
        pay = (40.0 * rate) + (1.5 * (hours - 40.0) * rate)
    return pay


try:
    hours = float(input( Enter Hours:  ))
    rate = float(input("Enter rate: "))
    pay = computepay(hours, rate)
    print( Pay:  , pay)

except:
    print("Invalid Input")

This code calculates the regular wage with flat rates and overtime with time-and-half for any work hours over forty(40) hours per work week.

hour = float(input( Enter hours:  ))

rate = float(input( Enter rates:  ))


def compute_pay(hours, rates):

if hours <= 40:

    print(hours * rates)

elif hours > 40:

    print(((hours * rate) - 40 * rate) * 1.5 + 40 * rate)



compute_pay(hour, rate )

This code calculates the regular wage with flat rates and overtime with time-and-half for any work hours over forty(40) hours per work week.

hour = float(input( Enter hours:  ))
rate = float(input( Enter rates:  ))

def compute_pay(hours, rates):

    if hours <= 40:
        pay = hours * rates
        return pay
    elif hours > 40:
        pay = ((hours * rate) - 40 * rate) * 1.5 + 40 * rate
        return pay

pay = compute_pay(hour, rate)
print(pay)




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签