我必须将这个Python代码编写为我的Logic类中的项目。我差不多完了它,但是当我尝试它时,我得到了这个错误:
Traceback (most recent call last):
这是什么意思,我该如何解决?
File "main.py", line 37, in <module>
opay = [(maxhrs - hworked) *orate] * prate
TypeError: can't multiply sequence by non-int of type 'float'
以下是我现在的代码:
while True:
cname = 'My Company'
drate = .17
maxhrs = 40
pdate = "9/1/2015"
orate = 1.5
lc = 'Y'
while(lc == 'Y'):
ename = raw_input("Enter employee's name.")
dcode = raw_input("Enter department code.(1 - Shipping 2 - Mngmt.)")
hworked = float(raw_input("Enter total hours worked."))
prate = float(raw_input("Enter your pay rate."))
inscost = float(raw_input("Enter the cost of insurance."))
city = float(raw_input("Enter your city code.(1 - Sumiton 2 - Hamilton)"))
st = raw_input("Enter your state")
sex = raw_input("Enter your sex.(M - Male F - Female)")
yrsemp = raw_input("Enter total years employed.")
print("Welcome to our company: ", cname)
print("Pay period date: ", pdate)
if(sex == 'M'):
sexword = 'Male'
else:
sexword = 'Female'
print("Employee name: ", ename, "Sex: ", sexword)
if(city == '1'):
cityn = 'Sumiton'
else:
cityn = 'Hamilton'
print("City: ", cityn, "State: ", state)
if(dcode == '1'):
dname = 'Shipping'
else:
dname = 'Management'
print("Department name: ", dname)
rpay = maxhrs * prate
print("Regular pay: ", rpay)
opay = [(maxhrs - hworked) * orate] * prate
print("Overtime pay: ", opay)
gross = rpay + opay
print("Gross before deduction: ", gross)
damt = drate * gross
print("Deduction amount: ", damt "Insurance cost: ", inscost)
npay = gross - (damt + icost)
print("Net pay: ", npay)
new = raw_input("Would you like to start over with a new person? yes/no")
if(new = 'yes')
restart = int(input("Press 1 to try again, 0 to exit. "))
if(restart == '1'):
continue
elif(restart == '0'):
break
else:
print("Invalid input. Please enter 1 to restart or 0 to exit.")
答案 0 :(得分:-1)
在Python 3.0中,评估字符串的2.x input()函数是
删除,以及2.x raw_input()函数,它只返回字符串 输入后,重命名为input()。
我是否应该添加任何特殊功能才能工作
在Python 3.0下正常使用?
x = int(输入(&#39; x:maxhrs&#39;)) y = int(输入(&#39; y:hworked&#39;))