import sys
def main_menu():
print("===============校园IT管理系统===============")
print("\t\t\t\t1、创建总部\t\t\t\t")
print("\t\t\t\t2、增加分校\t\t\t\t")
print("\t\t\t\t3、学生入学\t\t\t\t")
print("\t\t\t\t4、显示余额\t\t\t\t")
print("\t\t\t\t0、退出程序\t\t\t\t")
class Functions:
create_permission = True
@staticmethod
def init():
Subject("语文", 1000)
Subject("数学", 2000)
Subject("英语", 2500)
Subject("物理", 2300)
Subject("化学", 1800)
Subject("生物", 1900)
@classmethod
def create_head_school(cls):
if cls.create_permission:
ans = input("请输入学校名称,地址,电话号码以及网址,中间用空格隔开")
lst = ans.split()
School(lst[0], lst[1], lst[2], lst[3])
print("创建成功")
cls.create_permission = False
else:
print("只能存在一个总部,创建失败")
@staticmethod
def add_branch_school():
ans = input("哪个校区创办分校?")
if ans == School.sch.name:
obj = School.sch
School.add_branch_school(obj)
else:
for obj in BranchSchool.sch:
if ans == obj.name:
break
else:
obj = None
if obj:
BranchSchool.add_branch_school(obj)
else:
print("没有该学校,不能创建分校")
@staticmethod
def student_roll_in():
ans = input("请输入学生姓名,年龄,学校和想要学习的科目,中间用空格隔开")
lst = ans.split()
Student(lst[0], lst[1], lst[2], lst[3])
@staticmethod
def exit_prog():
print("程序退出")
sys.exit()
@staticmethod
def show_balance():
ans = input("请选择学校,若想查看全部请输入“总部”")
if ans == "总部":
print(School.total_balance)
else:
if ans == School.sch.name:
print(School.sch.balance)
else:
for item in BranchSchool.sch:
if ans == item.name:
print(item.balance)
break
else:
print("没有该学校")
def select_function():
dic = {1: Functions.create_head_school, 2: Functions.add_branch_school, 0: Functions.exit_prog,
3: Functions.student_roll_in, 4: Functions.show_balance}
ans = int(input("请选择一个功能"))
dic[ans]()
class School:
all_website = None
sch = None
branch_sch = []
total_balance = 0
total_stulist = []
total_stafflist = []
def __init__(self, name, address, phone, website=None):
self.name = name
self.address = address
self.phone = phone
self.website = website
self.maintain(self)
self.staff_list = []
self.stu_list = []
self.balance = 0
@classmethod
def maintain(cls, obj):
cls.all_website = obj.website
cls.sch = obj
print("总部创建成功")
def add_branch_school(self):
ans = input("请输入学校名称,地址和电话号码,中间用空格隔开")
lst = ans.split()
tmp = BranchSchool(lst[0], lst[1], lst[2])
tmp.father = self
# tmp.website = self.website
print("分部创建成功")
def calculate_balance(self):
print(self.balance)
def show(self):
print(self)
print(self.__dict__)
print(dir(self))
class BranchSchool(School):
all_website = None
sch = []
branch_sch = None
total_balance = None
total_stulist = None
total_stafflist = None
def __init__(self, name, address, phone, website=None):
super().__init__(name, address, phone, website)
self.website = super().all_website
self.father = None
super().branch_sch.append(self)
@classmethod
def maintain(cls, obj):
cls.sch.append(obj)
class Staff:
pass
class Teacher(Staff):
pass
class Student:
stulist = []
def __init__(self, name, age, subject, school):
self.name = name
self.age = age
self.subject = None
self.cla = None
self.school = None
self.send_subject(subject)
self.send_class()
self.send_school(school)
self.add_elem(self)
@classmethod
def add_elem(cls, obj):
cls.stulist.append(obj)
def send_subject(self, subject):
for item in Subject.sublist:
if item.name == subject:
item.stu_list.append(self)
self.subject = item
def send_class(self):
cl = self.subject.dic[self.subject.name]
if cl.cls_list:
obj = cl.cls_list[-1]
if obj.cur_num < obj.max_num:
obj.cur_num += 1
else:
cl(self.subject)
else:
cl(self.subject)
obj = cl.cls_list[-1]
self.cla = obj
obj.stu_list.append(self)
def send_school(self, school):
if school == School.sch.name:
School.sch.stu_list.append(self)
self.school = School.sch
else:
for item in BranchSchool.sch:
if school == item.name:
item.stu_list.append(self)
self.school = item
break
else:
print("没有这所学校")
return
self.school.balance += self.subject.price
School.total_balance += self.subject.price
School.total_stulist.append(self)
def change_school(self):
def show(self):
print(self.__dict__)
class Class:
max_num = -1
cls_list = []
def __init__(self, subject):
self.subject = subject
self.stu_list = []
self.cur_num = 1
self.add_elem(self)
def show(self):
print(self.__dict__)
@classmethod
def add_elem(cls, obj):
cls.cls_list.append(obj)
class Chinese(Class):
max_num = 2
cls_list = []
class Math(Class):
max_num = 3
cls_list = []
class English(Class):
max_num = 2
cls_list = []
class Physics(Class):
max_num = 2
cls_list = []
class Chemistry(Class):
max_num = 3
cls_list = []
class Biology(Class):
max_num = 2
cls_list = []
class Subject:
sublist = []
dic = {"语文": Chinese, "数学": Math, "英语": English, "物理": Physics, "化学": Chemistry, "生物": Biology}
def __init__(self, name, price):
self.name = name
self.price = price
self.add_element(self)
self.stu_list = []
@classmethod
def add_element(cls, obj):
cls.sublist.append(obj)
def show(self):
print(self.__dict__)
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
Functions.init()
while True:
main_menu()
select_function()
# School.sch.show()
# print(School.sch.all_website)
# if BranchSchool.sch:
# for it in BranchSchool.sch:
# it.show()
# print(it.all_website)
# print(Subject.sublist)
# for it in Subject.sublist:
# it.show()
#
# for it in Chinese.cls_list:
# print('语文')
# it.show()
#
# for it in Math.cls_list:
# print('数学')
# it.show()
#
# for it in English.cls_list:
# print('英语')
# it.show()
#
# for it in Physics.cls_list:
# print('物理')
# it.show()
#
# for it in Chemistry.cls_list:
# print('化学')
# it.show()
# for it in Biology.cls_list:
# print('生物')
# it.show()
#
# for it in Student.stulist:
# it.show()
12-24
08-24
9455
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-04