擅长:python、mysql、java
<p>在<code>Pension</code>中的<code>input</code>没有任何意义。您应该将数值属性强制转换为适当的类型(可能是<code>int</code>)。养老金本身也可能只是一个在<code>__init__</code>中计算一次的属性</p>
<pre><code>class Employee:
def __init__(self, emp_name, salary, yrs):
self.name = emp_name
#You know it's an employee, no need to have that in the attribute name too
self.yearly_salary = int(salary)
self.service = int(yrs)
self.pension = yearly_salary * service * .0015
</code></pre>
<p>然后构建<code>Employee</code>与任何其他对象相同的对象:</p>
<pre><code>e = Employee(name_in, salary_in, service_in)
print('Your pension is: {}'.format(e.pension))
</code></pre>