내 프로그램에서 직원 급여를 문자열로주고 그 금액에 int를 곱하고 있습니다."float 유형"이 아닌 정수로 시퀀스를 곱할 수 없습니다.
TypeError: can't multiply sequence by non-int of type 'float'
이 디버깅에 나를 간염하십시오
오류를 얻기.
class Employee:
raise_amt=1.2 # class variable
def __init__(self,first,last,pay):
self.first=first
self.last = last # instance variables
self.pay = pay
self.email = first+"."+last+"@company.com"
def fullname(self):
return '{}{}'.format(self.first,self.last)
def apply_raise(self):
self.pay= int(self.pay * self.raise_amt)
@classmethod # alter the raise amt
def set_raise_amt(cls,amount):
cls.raise_amt=amount
@classmethod
def from_string(cls,emp_str):
first,last,pay= emp_str.split('-')
return cls(first,last,pay)
emp_str_1='Nanda-kishor-90000' #values are in string
new_emp_1=Employee.from_string(emp_str_1)
Employee.set_raise_amt(2.2)
print(new_emp_1.raise_amt)
print(new_emp_1.pay)
new_emp_1.apply_raise()
print('after raise:',new_emp_1.pay)
출력 :
Traceback (most recent call last):
File "C:/Users/nanda.v/PycharmProjects/Python basics/practice continue and break statements.py", line 39, in <module>
new_emp_1.apply_raise()
2.2
File "C:/Users/nanda.v/PycharmProjects/Python basics/practice continue and break statements.py", line 19, in apply_raise
self.pay= int(self.pay * self.raise_amt)
90000
TypeError: can't multiply sequence by non-int of type 'float'