Python error calculating
I am having a problem with my code here. The error that I am receiving is on the bottom. I have to enter payroll in and calculate pay with overtime or without.
enter code here ####################### Functions ######################## def Input(): try: name=raw_input("Enter your first and last name: ") titlename=name.title() except: return Input
def Hours(): try: wHours=raw_input("Enter the hours you worked this week: ") except: if wHours < 1 or wHours > 60: print "Employees' can't work less than 1 hour or more than 60 hours." return lstEmp
def Pay(): try: pRate=raw_input("Enter your hourly wage: ") except: if pRate < 6 or pRate > 20: print "Employees' wages can't be lower than $6.00 or greater than $20.00." return pay
def calcHours(pr,h): if h <= 40: pr * h else: (h -40) *(pr *1.5) + pr * 40 return lstEmp
def end(): empDone=raw_input("Please type DONE when you are finished with employees' information: ") empDone.upper() == "DONE"
#################### MAINLINE CODElstEmp=[] Names=""
while True: Names=Input()
WorkHours=Hours()
Wages=Pay()
gPay=calcHours(WorkHours, Wages)
Done=end()
if end():
break
Traceback (most recent call last): File "J:11-2-10.py", line 53, in gPay=calcHours(WorkHours, Wages) File "J:11-2-10.py", line 29, in calcHours pr * h TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'
In Input, Hours and Pay, you assign to a variable of the same name as the functions; perhaps you mean to return these values instead?
gPay=calcHours(Hours, Pay)
You meant WorkHours
, which is what you called the variable; Hours
is still the function, that returned it. There are plenty of other places in the code where you've changed the variable names so they don't match any more.
Also +1 gnibbler's comment. That's really not what try
does, and you should never use except
without a particular Exception. The bit you might want to put in the try
is a conversion to integer:
def getHours():
while True:
hours= raw_input("Enter the hours you worked this week: ")
try:
hours= int(hours)
except ValueError:
print "That's not a number, type it proper."
continue
if not 1<=hours<=60:
print "Employees must work between 1 and 60 hours."
continue
return hours
链接地址: http://www.djcxy.com/p/56446.html
上一篇: 问题与xmlrpc服务器
下一篇: Python错误计算