-1

Ok I need help with this program. Here is the assignment

Write a payroll program that pays time and a half for anything over 40 hours. This should have 3 functions in addition to main.

  1. The first function asks the user how many total hours were worked and the pay rate and returns this information to main. These values must be validated. Hours worked must be at least 8 and no more than 86. Pay rate cannot be less than $7.00 or more than $50.00.
  2. The second function calculates the regular hours and overtime hours and returns this information to main. A person might work less than 40 hours so you must allow for that situation.
  3. The third function calculates the regular pay, (regular hours times pay rate); overtime pay, (overtime hours times overtime pay rate) and the total pay and returns this information to main.
  4. Main will then display this information on the screen like the sample below. (Values will have to be passed and returned).

The output should look something like the following:

             Payroll Information
Pay rate                           $10.00
Regular Hours                       40
Overtime Hours                      20
Regular pay                        $400.00
Overtime pay                       $300.00
Total Pay                          $700.00

And Here is what I have so far

def work_info():
    hw = input('Enter the amount of hours worked between 8 and 56')
    while hw < 8 or hw > 86:
        print('Enter the amount of hours in range')
    pr = input('Enter the your current payrate between $7 and $50')
    while pr < 7 or pr > 50:
        print('Enter a payrate in range')

def reg_ovt_hours():
    if hw < 40:
        reg_hours = hw and ovt_hours = 0
    else reg_hours > 40
        ovt_hours = hw - 40

    return hw

def reg_pay():
    reg_pay = reg_hours * pr
    ovt_pay = ovt_hours * reg_pay * 1.5
    tot_pay = reg_pay + ovt_pay
    return pr, reg_hours, ovt_hours

def main():
    print('Payroll Information')
    print ('Pay rate') pr
    print reg_hours
    print ovt_hours
    print reg_pay
    print ovt_pay
    print tot_pay

main() 

Please let me know how I can get this to work right

Blue Ice
  • 7,888
  • 6
  • 32
  • 52
user3290698
  • 1
  • 1
  • 1

2 Answers2

0

This line is wrong:

else reg_hours > 40

It should be

elif reg_hours > 40:

Or

else:

You were missing a colon, and you can't have a condition for else as it covers everything, well, "else".

What should happen if reg_hours == 40?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
0

You have to be aware of the scope with which variables are defined. I would recommend looking at a tutorial on the scope of variables in python.

I would recommend looking at this question: Short Description of the Scoping Rules?

For example in work_info you define hw and pr, but as it currently stands that's the only place where they are defined. So later when you try to use those variables you will get an error because the python interpreter doesn't know what they are.

Also you need to change else reg_hours > 40 to either else: or elif reg_hours > 40:

Community
  • 1
  • 1
shuttle87
  • 15,466
  • 11
  • 77
  • 106