class Employee():
def __init__(self, name, salary=0):
self.name = name
self.salary = salary
def hire(self):
hired = input('is employee hired? enter yes or no')
if 'yes' in hired:
hiresalary = int(input('enter employee salary'))
self.salary = hiresalary
def fire(self):
fired = input('is employee fired? enter yes or no')
if 'yes' in fired:
employeelist.remove(self.name)
if 'no':
pass
def raise_salary(self):
input("do you want to raise {}'s salary, enter yes or no".format(self.name))
if 'yes':
raise_sum = int(input("by how much do you want to raise {} salary?".format(self.name)))
self.salary += raise_sum
if 'no':
pass
我想知道是否有办法将类的每个实例都存储在一个列表中,以便在调用fire方法时可以从列表中删除该实例。你知道吗
正如上面提到的,您最好在
Employee
类之外存储一个员工列表。然后可以更改Employee.fire()
方法以接受员工列表,如下所示:相关问题 更多 >
编程相关推荐