Bigslimm21
Bigslimm21

Reputation: 15

Python payroll program looping error

I have this program I'm trying to write and I can't get it to stop asking the input over and over. Where is my error? Any help will do; I'm new at programming so this is all foreign.

def main():
    hours,rate = getinput()
    strtime,overtimehr,overtime = calculate_hours(hours)
    regular,overtime,totalpay  = calculate_pay(regular,overtimehr,rate)


def getinput():
    print ()
    print ('How many hours were worked?')
    print ('Hours worked must be at least 8 and no more than 86.')
    hours = float(input('Now enter the hours worked please:'))

    while hours < 8 or hours > 86: #validate the hours
        print ('Error--- The hours worked must be atleast 8 and no more than 86.')
        hours = float(input('Please try again:'))

    print ('What is the pay rate?')
    print ('The pay rate must be at least $7.00 and not more than $50.00.')
    rate = float(input('Now enter the pay rate:'))

    while rate < 7 or rate > 50: #validate the payrate
        print ('Error--- The pay rate must be at least $7.00 and not more than $50.00.')
        rate = float (input('Please try again:'))

        return hours, rate

    getinput()

def calculate_hours(hours):
    if hours < 40:
        strtime = hours
        overtime = 0
    else:
        strtime = 40
    overtimehr = hours - 40

    if hours > 40:
        overtimerate = 1.5 * rate
        overtime = (hours-40) * overtimerate
        hours = 40
    else:
        overtime = 0

    return strtime, overtime, overtimehr

    calculate_hours(hours)

def calculate_payregular(regular,totalpay,rate):
    regular = hours * rate
    totalpay = overtime + regular

    return regular, totalpay,rate

    calculate_payregular(regular,totalpay,rate)


def calprint (rate, strtime, overtimehr, regular, overtime, totalpay):
    print ("           Payroll Information")
    print ()
    print ("Pay rate                $", format (rate,  '9,.2f'))
    print ("Regular Hours            ", format (strtime,  '9,.2f'))
    print ("Overtime hours           ", format (overtimehr,  '9,.2f'))
    print ("Regular pay             $", format (regular,  '9.2f'))
    print ("Overtime pay            $", format (overtime,  '9.2f'))
    print ("Total Pay               $", format (totalpay,  '9.2f'))

    calprint (rate, strtime, overtimehr, regular, overtime, totalpay)

main ()

Upvotes: 0

Views: 509

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599628

All your functions, including getinput(), appear to be calling themselves at the end, which is probably the cause of your problem. You don't need that last line in any of your functions - I'm not sure why you think you do. Remove it from all of them.

Also I expect return hours, rate should be un-indented one level.

Upvotes: 1

Related Questions