55.9k views
4 votes
In Python please:

For below program, please follow the rule that people who get paid at least $375 are paid by direct deposit to their bank account; everyone else (who is paid less than $375) gets paid by check in the mail.
1. Write a simple program (using conditionals) that calls the compute_pay function, stores the result in a variable pay_for_week, and prints "Paying x by direct deposit" if pay_for_week is at least 375, and "Paying pay_for_week by mailed check if x is less than 375. Here are some test cases:
a. If the number of hours worked is 45, and the rate of pay is 10, you should print "Paying 475 by direct deposit"
b. If the number of hours worked is 35, and the rate of pay is 10, you should print "Paying 350 by mailed check"
c. If the number of hours worked is 63, and the rate of pay is 10, you should print "Paying 745 by direct deposit"

1 Answer

4 votes

Answer:

def compute_pay(number_of_hours, rate_of_pay):

if number_of_hours > 40:

pay_for_week = (40*rate_of_pay)+((number_of_hours-40)*\

(rate_of_pay+rate_of_pay*0.5))

else:

pay_for_week = number_of_hours*rate_of_pay

if pay_for_week >= 375:

print("Paying %d by direct deposit" % pay_for_week)

else:

print("Paying %d by mailed check" % pay_for_week)

Step-by-step explanation:

  1. We define the computer pay function that receives the number of hours worked in a week and the rate of pay
  2. From the test cases we deduce that if a worker works more than 40 hours a week an extra payment is given, you can calculated it as follow: (40 * rate_of_pay) + ((number_of_hours - 40) * (rate_of_pay + rate_of_pay * 0.5))
  3. If a worker works less than 40 hours the payment is calculated as follow: pay_for_week = number_of_hours * rate_of_pay
  4. If the pay for week is equal or greater than 375 we print a payment by direct deposit otherwise we print payment by mailed check
In Python please: For below program, please follow the rule that people who get paid-example-1
User Sheikh Ali
by
3.6k points