class staff:
ID=123456
name="www"
age=18
salary=4000
def display(self):
print(str(staff.ID)+" "+staff.name+" "+str(staff.age)+" "+str(staff.salary))
def __init__(self,ID,name,age,salary):
self.salary=staff.salary
self.ID=staff.ID
self.name=staff.name
self.age=staff.age
def __str__(self):
return 'staff1:'+str(self.ID)+' '+self.name+' '+str(self.age)+' '+str(self.salary)
class staff2(staff):
def __init__(self):
self.ID=345678
self.name='ttt'
self.age=20
self.salary=10000
print('staff2:',self.ID,self.name,self.age,self.salary)
class numerror(Exception):
pass
class staff3(staff):
def __init__(self):
self.ID=234
self.name='rrr'
self.age=200
self.salary=20
print("staff3:",self.ID,self.name,self.age,self.salary)
try:
i=self.ID
if i<10000 or i>100000:
raise numerror
except ValueError:
print("不是整数")
except numerror:
print("staff3工号范围错误")
try:
i=self.age
if i<1 or i>120:
raise numerror
except ValueError:
print("不是整数")
except numerror:
print("staff3年龄范围错误")
try:
i=self.salary
if i<100 or i>100000:
raise numerror
except ValueError:
print("不是整数")
except numerror:
print("staff3工资范围错误")
s=staff(1234,"ppp",25,8000)
s.display()
print(s)
s2=staff2()
s3=staff3()