TypeError: int() argument must be a string or a number, not 'tuple'

I'm trying to figure out this error for this homework assignment I'm working on. It's suppose to be a payroll program that calculates pay and overtime pay, with overtime defined as any amount of hours over 40.


My Error:

Traceback (most recent call last):
  File "C:\Python33\Assignment6.py", line 79, in <module>
    main()
  File "C:\Python33\Assignment6.py", line 18, in main
    original_pay = calculate_pay(original_hours, original_rate)
  File "C:\Python33\Assignment6.py", line 52, in calculate_pay
    original_hours = int(original_hours)
TypeError: int() argument must be a string or a number, not 'tuple'

My code:

overtime_rate_constant = .5

overtime_limit = 40

overtime_hours = 0

def main ():
    greet()
    original_hours = get_hours()
    original_rate = get_rate()
    original_pay = calculate_pay(original_hours, original_rate)
    totalpay = overtime_pay + original_pay
    print_data(original_rate, overtime_hours, original_hours, calculate_overtime_hours, original_pay, totalpay)

def get_hours ():    

    original_hours = int(input("Please enter hours worked (8-86): "))
    print()

    while original_hours < 8 or original_hours > 86:
        print("You must enter between 8 - 86 hours.")
        print()
        original_hours = int(input("Please try again: "))
        print()


    original_hours = int(original_hours)
    for original_hours in range (41, 86):
        overtime_hours = original_hours - overtime_limit
        return original_hours, overtime_hours    
    return original_hours   
def get_rate ():

    original_rate = int(input("Please enter your hourly rate: "))
    print()
    while original_rate < 7 or original_rate > 50:
        print("You must enter a pay rate between 7 - 50 dollars")
        print()
        rate = int(input("Please try again: "))
        print()
        return original_rate
    return original_rate
def calculate_pay (original_hours, original_rate):

    original_hours = int(original_hours)
    original_rate = int(original_rate)

    original_pay = original_hours * original_rate
    overtime_pay = original_hours * original_hours + overtime_hours * .5

    return overtime_pay, original_pay

def print_data (original_rate, overtime_hours, original_hours, overtime_pay, original_pay, totalpay):

    print()
    print("Pay rate:       $", format (original_rate, '0,.2f'))
    print("Regular Hours:   ", format (original_hours, '0,.0f'))
    print("Overtime Hours:  ", format (overtime_hours, '0,.0f'))
    print("Regular Pay:    $", format (original_pay, '0,.2f'))
    print("Overtime Pay:   $", format (overtime_pay, '0,.2f'))
    print("Total Pay:      $", format (totalpay, '0,.2f'))

def greet ():
    print("This program calculates pay.")
    print()






main()

Answers


I didn't see that it was an assignment for you. Anyway, focus on variable assignment, then if you return n value(s), receive that with n variables from where you are calling otherwise, you will get the following error:

TypeError: int() argument must be a string or a number, not 'tuple'

Your program was kind of mess. Now, it's been fixed!

overtime_rate_constant = .5

overtime_limit = 40

overtime_hours = 0

def main ():
    greet()
    original_hours,overtime_hours = get_hours()
    original_rate = get_rate()

    overtime_pay, original_pay = calculate_pay(original_hours, original_rate)
    totalpay = overtime_pay + original_pay
    print_data(original_rate, overtime_hours, original_hours, overtime_pay, original_pay, totalpay)

def get_hours ():    

    original_hours = int(input("Please enter hours worked (8-86): "))
    print()

    while original_hours < 8 or original_hours > 86:
        print("You must enter between 8 - 86 hours.")
        print()
        original_hours = int(input("Please try again: "))
        print()


    #original_hours = int(original_hours)
    for original_hours in range (41, 86):
        overtime_hours = original_hours - overtime_limit
    return original_hours, overtime_hours    
    #return original_hours   
def get_rate ():

    original_rate = int(input("Please enter your hourly rate: "))
    print()
    while original_rate < 7 or original_rate > 50:
        print("You must enter a pay rate between 7 - 50 dollars")
        print()
        rate = int(input("Please try again: "))
        print()
        return original_rate
    return original_rate
def calculate_pay (original_hours, original_rate):

    original_hours = int(original_hours)
    original_rate = int(original_rate)

    original_pay = original_hours * original_rate
    overtime_pay = original_hours * original_hours + overtime_hours * .5

    return overtime_pay, original_pay

def print_data (original_rate, overtime_hours, original_hours, overtime_pay, original_pay, totalpay):

    print()
    print("Pay rate:       $", format (original_rate, '0,.2f'))
    print("Regular Hours:   ", format (original_hours, '0,.0f'))
    print("Overtime Hours:  ", format (overtime_hours, '0,.0f'))
    print("Regular Pay:    $", format (original_pay, '0,.2f'))
    print("Overtime Pay:   $", format (overtime_pay, '0,.2f'))
    print("Total Pay:      $", format (totalpay, '0,.2f'))

def greet ():
    print("This program calculates pay.")
    print()

main()

You missed different things in your program. I sorted it out. I am also showing the errors I fixed:

Error 1:

Traceback (most recent call last):
  File "p.py", line 72, in <module>
    main()
  File "p.py", line 11, in main
    original_pay = calculate_pay(original_hours, original_rate)
  File "p.py", line 45, in calculate_pay
    original_hours = int(original_hours)
TypeError: int() argument must be a string or a number, not 'tuple'

Error 2:

Traceback (most recent call last):
  File "p.py", line 72, in <module>
    main()
  File "p.py", line 12, in main
    totalpay = overtime_pay + original_pay
NameError: global name 'overtime_pay' is not defined

Error 3:

Traceback (most recent call last):
  File "p.py", line 73, in <module>
    main()
  File "p.py", line 14, in main
    print_data(original_rate, overtime_hours, original_hours, calculate_overtime_hours, original_pay, totalpay)
NameError: global name 'calculate_overtime_hours' is not defined

Your calculate_pay() function doesn't handle overtime properly. Be sure to pass the values in the tuple returned by get_hours() properly, and make sure that get_hours() always returns a 2-tuple, even if the second element is 0.


The problem is in this line (in your get_hours function):

return original_hours, overtime_hours

This is returning a tuple.


Need Your Help

Real Time Javascript Event Tracking (Javascript Stats)

javascript events google-analytics tracking

There are lots of real time web stats services on the web (w3counter-histats-gostats).They just count once when page is requested , But what I want to do is track javascript functions/events, becau...