Answer:
# Initialize the values
overtime_pay = 0
deduction = 0
# Ask the user to enter hours and shift
hours = int(input("Enter hours worked: "))
shift = int(input("Enter shift[1/2/3]: "))
# Check the shift. If it is 1, set the hourly rate as 17
# If the shift is either 2 or 3, ask for participation to retirement plan
# If shift is 2, set the hourly rate as 18.50
# If shift is 3, set the hourly rate as 2
if shift == 1:
horly_pay_rate = 17
elif shift == 2 or shift == 3:
retirement = int(input("Participate in the retirement plan? [1 for yes, 2 for no]: "))
if shift == 2:
horly_pay_rate = 18.50
if shift == 3:
horly_pay_rate = 22
# Check the hours. If it is smaller than or equal to 40, calculate only regular pay
# If hours is greater than 40, calculate regular and overtime pay
if hours <= 40:
regular_pay = (hours * horly_pay_rate)
elif hours > 40:
regular_pay = (40 * horly_pay_rate)
overtime_pay = (hours - 40) * (horly_pay_rate * 1.5)
#calculate total pay
total_pay = regular_pay + overtime_pay
# Check the retirement. If it is 1, calculate and apply deduction
if retirement == 1:
deduction = total_pay * 0.03
net_pay = total_pay - deduction
else:
net_pay = total_pay
#print the results
print("Hours worked: " + str(hours))
print("Shift: " + str(shift))
print("Hourly pay rate: " + str(horly_pay_rate))
print("Regular pay: " + str(regular_pay))
print("Overtime pay: " + str(overtime_pay))
print("Total of regular and overtime pay: " + str(total_pay))
print("Retirement deduction: " + str(deduction))
print("Net pay: " + str(net_pay))
Explanation:
*See the comments in the code