I need help with this problem!
I can't get all three to display.
Write a program that prompts a user to enter their hourly pay and rate. Understanding that "time and a half" applies to hours in excess of forty, calculate and print the user's regular pay, overtime pay, and total pay for the week.

Please add code for us to look at.

These are a couple I've tried so far

print("Enter hours and rate for total pay")
rate = float(input("Enter the hourly pay rate: "))
hours = float(input('Enter the hours worked last week: '))
if hours < 40 :
    print(f" Regular pay: {hours*rate}")
else :
    print(f" Overtime pay: {40*rate + (hours - 40)*rate*1.5}")

#
rate = float(input("Enter the hourly pay rate: "))
hours = float(input("Enter the hours worked last week: "))
ovt = hours-40
if hours < 40 : 
    print(f" Regular pay: {hours*rate}")
else :
    print(f" Overtime pay: {ovt*rate(1.5)}")
    print(f" Total pay: {ovt +(hours*rate)}")
commented: The regular pay is never displayed when you have overtime pay because of the if/else block you've used. To fix, just remove the if/else statements +0

For hours less than 40 I see 2 print lines that will execute. Lines 5 and 14.
For hours 40 and over, only line 16 and 17 will print.

Your code does exactly what you told it to do.

Plug in a few test numbers. What happens if only 35 hours are worked? In that cast the overtime is -5 hours and you get a negative OT pay. Write your program in pseudo-code. Write out the steps you would do if you were doing the accounting by hand. Try out a few numbers like 35, 40, and 45 to see if you get sensible results.

This is the out put my code give. I need it to display the regular pay, overtime pay and total pay all together.

= RESTART: /Users/shiannegandarillas/Desktop/COP 1100/Gandarillas3/program3_1.py
Enter hours and rate for total pay
Enter the hourly pay rate: 10
Enter the hours worked last week: 50
 Overtime pay: 550.0

= RESTART: /Users/shiannegandarillas/Desktop/COP 1100/Gandarillas3/program3_1.py
Enter hours and rate for total pay
Enter the hourly pay rate: 10
Enter the hours worked last week: 40
 Overtime pay: 400.0

In English, what you want is

  1. Calculate the number of regular hours worked
  2. Calculate the number of overtime hours worked
  3. Print the regular pay amount
  4. If there was overtime, print the overtime pay amount and the total amount

Just turn that into code.

commented: I understand that. I can't get the code to behave correctly that's what I need help with. +0

Is there anyone who can help explain the code to make this work correctly? All replies here have not been helpful

commented: Rprofitt is correct, the code does what you told it to. You seem to misunderstand what the if/else statements do. +0

I'm doing everything I can other than write the code for you. Take each of the steps I gave you and convert to code. If it doesn't work, then repost the code and I'll explain why it doesn't match what I said. I suggest you make each pseudo-code step into a comment and add the actual code after each comment.

Do not start a new thread with the same question just because you don't like the responses you are getting in this one. If you keep trying here we will eventually get you through it.

If you break down each process, to see if your calculations are correct, it would be easier to see where things are not working. I did that for you in this example.

print("Enter hours and rate for total pay")
rate = float(input("Enter the hourly pay rate: "))
hours = float(input("Enter the hours worked last week: "))

reg_wage = rate * hours

reg_pay = 40 * rate
ot_reg_wage = rate * hours

ot_hours = hours - 40
ot_rate = rate*1.5
ot_wage = ot_hours * ot_rate

total_ot_wage =  ot_wage

if hours > 40:
  print(" Regular hours ", 40)
  print(" Regular rate: ""$", rate)
  print(" Regular pay: ""$", reg_pay) 
  print(" Overtime hours: ", ot_hours)
  print(" Overtime rate:""$", ot_rate)
  print(" Overtime pay: ""$", ot_wage)
  print(" Total Wage: ""$", total_ot_wage + reg_pay)
if hours < 40:
  print(" Regular hours: ", hours)
  print(" Regular rate: ""$",rate)
  print(" Regular pay: ""$",reg_wage)
  print(" Total Wage: ""$",reg_wage)
commented: You are not helping by writing the code for them. -3

And, what exactly did the OP learn by you writing the code for them?

commented: They learn when the teacher does a web search. Also, I didn't write it and gave attribution. It's a wonder why folk want code that is on the web. +16
commented: I learned what I needed. I am I visual learner. I need to see the code so I could evaluate it and understand the difference between mine and this. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.