'''Employee 类
- 员工数 初始值为0, 每当新声明一个实例时,员工数加一
- 员工: 姓名, 工资
- 声明方法 displayCount: 打印出当前的总员工数
- displaySalary : 打印每一个员工自己的名字和薪水.'''
class Employee:
displayCount
=0
def __init__(self
,name
,salary
):
self
.name
=name
self
.salary
=salary
Employee
.displayCount
+= 1
def Count(self
):
print('当前员工数为:',Employee
.displayCount
)
def displaySalary(self
):
print('员工名字:%s \t员工薪水:%s'%(self
.name
,self
.salary
))
if __name__
== '__main__':
while True:
name
=input('输入名字:')
salary
=input('请输入薪水!')
Employee1
=Employee
(name
,salary
)
Employee1
.Count
()
Employee1
.displaySalary
()
转载请注明原文地址: https://mac.8miu.com/read-502581.html