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()

Recommended Answers

All 2 Replies

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.