python - NameError: global name 'totaloverpay' is not defined -


i started college , writing code out college class , keeps sending error. enlightenment help, maybe problem i'm half asleep.

here code

def main():     overtime = int(0)     totaloverpay = float(0)     hours = int(input('how many hours did work? note** hours can not exceed 86 or less 8 '))     while hours > 86 or hours < 8:         print('error: insufficient input. try again')         hours = int(input('how many hours did work? note** hours can not exceed 86 or less 8 '))      payrate = float(input('what payrate per hour employee? note** payrate can not exceed $50.00 or less $7.00 '))     while payrate > 50.00 or payrate < 7.00:             print('error: insufficient input. try again')             payrate = float(input('what payrate per hour employee? note** payrate can not exceed $50.00 or less $7.00 '))      workhours(hours, payrate, overtime) def workhours(hours, payrate, overtime):     if hours > 40:         overtime = (hours - 40) * -1     else:         regtime = hours + 0     paydistribution(hours, payrate, regtime, overtime) def paydistribution(hours, payrate, regtime, overtime):     if hours >= 40:         halfrate = float(payrate * 0.5)         overpay = halfrate + payrate         totaloverpay = float(overpay * hours)     if hours < 40:         regpay = hours * payrate      display(hours, payrate, regpay, regtime, overtime) def display(hours, payrate, regpay, regtime, overtime):     total = float(regpay + totaloverpay)      print('     payroll information')     print('payrate       :', format(payrate, '0.2f'))     print('regular hours :', format(regtime))     print('overtime hours:', format(overtime))     print('regular pay   :', format(regpay, '6.2f'))     print('overtime pay  :', format(totaloverpay, '7.2f'))     print('total pay     :', format(total, '7.2f'))  main() 

totaloverplay not defined in function below main in referred to, or global variable. if want global, define outside of main function's scope.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -