def apply_raise
无法激活。为什么?请帮助我
class Employee():
raise_amount = 1.1
raise_percentage = 10
def __init__(self,name,education,age,wage):
self.name = name
self.education = education
self.age = age
self.wage = wage
def __str__(self):
return "안녕하세요.저는 %s 입니다. 저의 학력은 %s 입니다." %(self.name, self.education)
def apply_raise(self,raise_percentage,wage):
print('%d%% 인상되어 연봉은 %s입니다.'%(self.raise_percentage, self.wage))
self.wage = int(self.wage * self.raise_amount)
self.raise_percentage = (self.raise_amount-1)*100
return
taedragon = Employee('Taedragon', '로스쿨졸업', 31, '20000')
taedragon.apply_raise(10, 22000)
错误:
self.wage = int(self.wage * self.raise_amount)
TypeError: can't multiply sequence by non-int of type 'float'
答案 0 :(得分:1)
原因是这一行:
taedragon = Employee('Taedragon', '로스쿨졸업', 31, '20000')
您正在传递{<1>},它是一个字符串。您不能将字符串与浮点数相乘。
执行此操作:
wage='20000'
答案 1 :(得分:1)
实例化taedragon = Employee('Taedragon', '로스쿨졸업', 31, 20000)
时,最后一个参数应为Employee
而不是20000
(您必须传递数字类型而不是字符串类型)