#!/usr/bin/python3
#schoolmis.py
import datetime
class person:
def __init__(self,nid,name,gender,birthday):
def isrunnian(year):
if (year%4==0 and year%400==0) or (year%4==0 and year%100!=0) :
return True
else :
return False
def isdate(*args):
if args[0]<0 or args[1]<0 or args[1]>12 or args[2]<0 or args[2]>31 :
return False
if isrunnian(args[0]) and args[1]==2 and args[2]<=29 :
return True
if args[1] in [1,3,5,7,8,10,12] :
if args[2]<=31 :
return True
else :
return False
else :
if args[2] <=30 :
return True
else :
return False
if not (isinstance(name,str) and gender in ("F","M")):
raise ValueError("gender:",gender)
if not isdate(*birthday) :
raise ValueError("birthday:",birthday)
try:
birth=datetime.date(*birthday)
except:
raise ValueError("birthday:",birthday)
self._nid=nid
self._name=name
self._gender=gender
self._birthday=birth
def __str__(self):
return ",".join((self._nid,self._name,self._gender,str(self._birthday)))
def birthday(self):
return self._birthday
def gender(self):
return self._gender
def name(self):
return self._name
def nid(self):
return self._nid
class student(person):
def __init__(self,nid,name,gender,birthday,study):
super().__init__(nid,name,gender,birthday)
self._study=study
self._score=dict()
def __str__(self):
return ",".join((super().__str__(),self._study))
def setscore(self,courseid,score):
self._score[courseid]=score
def score(self,courseid):
return self._score[courseid]
def scores(self):
return self._score
def setstudy(self,study):
self._study=study
def study(self):
return self._study
class manager(person):
def __init__(self,nid,name,gender,birthday,office):
super().__init__(nid,name,gender,birthday)
self._office=office
def __str__(self):
return ",".join((super().__str__(),self._office))
def setoffice(self,office):
self._office = office
def office(self):
return self._office
class teacher(person):
def __init__(self,nid,name,gender,birthday,department):
super().__init__(nid,name,gender,birthday)
self._department=department
def __str__(self):
return ",".join((super().__str__(),self._department))
def setdepartment(self,department):
self._department=department
def department(self):
return self._department
if __name__=="__main__" :
p1=person("001","张三","M",(2000,1,1))
print(p1)
print(p1.nid(),p1.name(),p1.gender(),p1.birthday())
s1=student("00001","王五","M",(2002,2,28),"哲学")
print(s1)
s1.setstudy("会计学")
s1.setscore("B001",89)
s1.setscore("B002",91)
print(s1)
print(s1.nid(),s1.name(),s1.gender(),s1.study(),s1.study(),s1.score("B001"),s1.scores())
t1=teacher("0001","元元","M",(1989,9,23),"讲师")
print(t1)
t1.setdepartment("副教授")
print(t1.department())
m1=manager("0002","白云","F",(1971,3,4),"教务处")
print(m1)
m1.setoffice("科技处")
print(m1.office())