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.

Recommended Answers

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

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, networking, learning, and sharing knowledge.