I'm not very good at Python as you can tell from my earlier posts.

I'm trying to write a payroll program that gets the input from the user of how many hours worked and the hourly rate and calculates the total wages for the week. It also has to figure over-time-hours by paying anything over 40 hours time-and-a-half(* 1.5). I want to set it up into four functions though. So, the first function would ask for the hours and pay rate. The second would calculate the regular hours and overtime hours. The third would calculate regular pay and overtime pay and the total pay. Then the fourth(main) would display the info something like this....

Pay rate \$10.00
Regular Hours 40
Overtime hours 20
Regular pay \$400.00
Overtime pay \$300.00
Total Pay \$700.00

(Just example numbers)

This is what I have so far.

``````def hours():
hours = input("How many hours did you work?:")
return hours
def payrate():
payrate = input("How much is the payrate?:")
return payrate
def calchours(pr,h):
if h > 40:
overtime = pr * h *1.5
print overtime
elif h < 40:
reg = pr * h
print reg
def main():
hrs = hours()
pyr = payrate()
calchours (pyr, hrs)
main()``````

I'm not sure on how to handle the input of hours and payrate in the same function or how to display all the information in main. I definitely need it all organized within four functions though. If someone could help make sense of this that would be exteremely generous.

Thanks for your time.

## All 5 Replies

Seems to be too simple to be homework. You were almost there, you should only multply the overtime pay by 1.5.

``````"""
output should be:
Pay rate \$10.00
Regular Hours 40
Overtime hours 20
Regular pay \$400.00
Overtime pay \$300.00
Total Pay \$700.00
"""
def hours():
hours = input("How many hours did you work?: ")
return hours

def payrate():
payrate = input("How much is the payrate?: ")
return payrate

def calchours(pr, h):
if h > 40:
rh = 40
oh = h - 40
else:
rh = h
oh = 0
print "Pay rate \$%0.2f" %  pr
print "Regular Hours %d" % rh
print "Overtime hours %d" % oh
print "Regular pay \$%0.2f" % (rh * pr)
print "Overtime pay \$%0.2f" % (oh * pr * 1.5)
print "Total Pay \$%0.2f" % (rh * pr + oh * pr * 1.5)

def main():
hrs = hours()
pyr = payrate()
calchours (pyr, hrs)

main()``````

Wow, that's great. Thank you so much for your help.

can you help me to create a program this?

Write a simple payroll program to compute the salary of employee using Objects and Classess in Python and will execute the following and display output on the screen.

``````(A) Add
(E) Edit
(D) Delete
(S) Search
(X) Exit``````

Please read the Daniweb Posting Rules and Suggestions For Posting Questions.

Short version:

1. Don't hijack threads. Start a new on with your question.
2. Don't resurrect old threads.
3. Show what you have done so far and where you are stuck.
commented: +1 +16

great!

Be a part of the DaniWeb community

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