Rewrite a pay computation with time-and-a-half for overtime and create a function called computepay which takes two parameters(hours and rate0

Question:

Here is my code (btw I am new to Stackoverflow and coding in general so forgive me if I made some mistakes in formatting this question):

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)
Asked By: S R

||

Answers:

To take into account overtime versus regular rates of pay it seems like you will need to know how much time the employee worked in each category. With that in mind, here is a simplified example to illustrate some of the key concepts.

Example:

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}")

Output:

Hourly rate in dollars:  15.00
Regular hours worked:  40
Overtime hours worked:  10
This pay period you earned: $825.00
Answered By: rhurwitz

My teacher told me to solve it in one function, computerpay . so try this .

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

Then The input Output Part

sh = input("enter Hours:")
sr = input(" Enter rate:")
fh = float(sh)
fr = float(sr)
xp = computepay(fh,fr)
print("Pay:",xp)
Answered By: Naem Azam
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)
Answered By: Thomas Dambreville
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)
Answered By: Josh
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)
Answered By: Josh
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.