0

I'm trying to call up the pay, overtime, and totalpay that I get out of the second function. How do I do that? I think that's my problem. I get the following errors when I run the program:

How many hours did you work? 50
What is your rate of pay? 10

Traceback (most recent call last):
  File "C:\Documents and Settings\R o n\Desktop\me\Programming\paychp71.py", line 47, in -toplevel-
    main()
  File "C:\Documents and Settings\R o n\Desktop\me\Programming\paychp71.py", line 26, in main
    findpay(hours, rate)
  File "C:\Documents and Settings\R o n\Desktop\me\Programming\paychp71.py", line 22, in findpay
    totalpay = pay + overtime
UnboundLocalError: local variable 'pay' referenced before assignment
def ask_hours():
          hours = float(raw_input ("How many hours did you work? "))
          rate = float(input ("What is your rate of pay? "))
          return hours, rate
     
def findpay(hours, rate):
         if hours <= 40:
             pay = hours * rate
         if hours > 40:
             overtime = (hours - 40) * (rate * 1.5)
             totalpay = pay + overtime
         return pay, overtime, totalpay                       
def main() :
        hours, rate = ask_hours()
        findpay(hours, rate)
        print "Pay rate", rate
        if hours <= 40:
            print "Regular hours", hours
        elif hours >= 40:
            print "Regular hours", 40
        print "Overtime hours", (hours - 40)
        if hours <= 40:
            print "Regular pay", pay
        elif hours > 40:
            print "Regular pay", (40 * rate)
        if hours < 40:
            print "Overtime Pay", 0
        elif hours > 40:
            print "Overtime Pay", overtime
        if hours <= 40:
            print "Total Pay", pay
        elif hours > 40:
            print "Total Pay", totalpay

               
main()
2
Contributors
2
Replies
5
Views
8 Years
Discussion Span
Last Post by strictlycustom
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.