擅长:python、mysql、java
<p>创建<code>Employee</code>类:</p>
<pre><code>class Employee:
def __init__(self, name, salary, yrs):
self.name = name
self.yearly_salary = int(salary)
self.service = int(yrs)
def Pension(self):
pen_total = int(self.yearly_salary * self.service * .0015) # Use self to access the attributes and methods of the class
return pen_total
</code></pre>
<p>获取员工详细信息:</p>
<pre><code>name_in = input("Please enter a name: ")
salary_in = input("Please enter salary: ")
years_in = input("Please enter years of service: ")
</code></pre>
<p>实例化类:</p>
<pre><code>emp = Employee(name_in, salary_in, years_in)
</code></pre>
<p>打印养老金:</p>
<pre><code>print('Your monthly pension payout is ${}'.format(emp.Pension()))
</code></pre>