Python如何实现学校管理系统

这篇文章主要介绍了Python如何实现学校管理系统,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

一、功能分析

此学校管理系统应该可以实现学校的师资力量的调配,学生的入学、学习以及修学或者退学的情况

二、程序解读

1.下面的程序实现了学校管理系统的基本功能,包括:

1)学校的招生 2)讲师的招聘 3)课程的增加 4)等等

2.未实现的功能也有很多,比如:

1)学生类中有一个方法是缴费,也有一个方法是注册,这两个方法应该关联起来,缴费成功后,才可以进行注册 2)每个老师应该可以通过各种方式来查看自己学生的信息,比如按照姓名,学号等等 3)每个学生都应该可以查看学校所有的课程和教师情况 4)所有的这些信息必须保存在文件或者数据库中才可以得到永久的保存 5)在客户上传相应的数据时,应该对其有所约束,比如说学号必须是10位正整数(在这里,为了避免报错,将所有的数据都设置为字符串型) 6)讲师,学生和课程的删除,修改,查询等操作需要添加 7)各类对象在初始化的时候需要输入的信息太多,应该做成只需要唯一ID和PASSWD这种类型的来进行相应的登录 8)等等

二、程序代码

#!/usr/bin/envpython
#coding:utf-8
"""
file:Management.py
date:9/9/179:57PM
author:hx
desc:管理系统雏形
"""
##添加模块
importsys
importjson

##学校类定义
classSchool(object):
##初始化函数
def__init__(self,SchoolName,SchoolPlace,SchoolMotto):
self.SchoolName=SchoolName
self.SchoolPlace=SchoolPlace
self.SchoolMotto=SchoolMotto
##招生函数
defRecruitStu(self):
NewStuName=raw_input("StuName:")
NewStuAge=raw_input("StuAge:")
NewStuSex=raw_input("StuSex:")
NewStuSchool=raw_input("StuSchool:")
CourseNo=raw_input("CourseNo:")
NewStuID=raw_input("StuID:")
CoursePrice=raw_input("CoursePrice:")
NewStu=Stu(NewStuName,NewStuAge,NewStuSex,NewStuSchool,CourseNo,NewStuID,CoursePrice)##实例化学员对象
stus_dict={"StuName":NewStuName,"StuAge":NewStuAge,"StuSex":NewStuSex,"StuSchool":NewStuSchool,"CourseNo":CourseNo,"StuID":NewStuID,"CoursePrice":CoursePrice}#用字典来存放讲师信息
ifnotdic:
dic[NewStuName]=stus_dict
json.dump(dic,open("student_db","w"),encoding='utf-8',ensure_ascii=False,indent=2)
else:
ifdic.get(NewStuName):
print("%s学生已存在,不能注册名字相同的学生"%NewStuName)
else:
dic[NewStuName]=stus_dict
json.dump(dic,open("student_db","w"),encoding='utf-8',ensure_ascii=False,indent=2)
print("Thestudenthasalreadyaddedsuccessfully".center(50,'-'))
NewStu.StuInfo()
##聘请讲师
defHireTch(self):
print"Welcometohireteacherfromhere~"
NewTeacherName=raw_input("Pleaseinputtheteacher'sname:")
NewTeacherAge=raw_input("Pleaseinputtheteacher'sage:")
NewTeacherSex=raw_input("Pleaseinputtheteacher'ssex:")
NewCourseNo=raw_input("Pleaseinputtheteacher'scoursenumber:")
NewSalary=raw_input("Pleaseinputtheteacher'ssalary:")
NewTeacher=Teacher(NewTeacherName,NewTeacherAge,NewTeacherSex,NewCourseNo,NewSalary)#实例化讲师对象
teachers_dict={"TeacherName":NewTeacherName,"TeacherAge":NewTeacherAge,"TeacherSex":NewTeacherSex,"CourseNo":NewCourseNo,"Salary":NewSalary}#用字典来存放讲师信息
#通过json将讲师的字典反序列化到dic字典中
ifnotdic:#字典如果为空
dic[NewTeacherName]=teachers_dict#将讲师名与讲师对象相关联
#通过json将讲师的字典序列化到teacher_db文件中
json.dump(dic,open("teacher_db","w"),encoding='utf-8',ensure_ascii=False,indent=2)
else:#如果文件中已有讲师信息
ifdic.get(NewTeacherName):#字典中不存在key,则返回none,不报错
print("%s讲师已存在,不能创建名字相同的讲师"%NewTeacherName)
else:
dic[NewTeacherName]=teachers_dict
json.dump(dic,open("teacher_db","w"),encoding='utf-8',ensure_ascii=False,indent=2)
NewTeacher.TeacherInfo()##将新老师的信息打印在屏幕上

##新增课程
defCreateCourse(self):
print"Welcometocreatecourse!"
NewCourseNo=raw_input("CourseNo:")
NewCourseName=raw_input("CourseName:")
NewCoursePrice=raw_input("CoursePrice:")
NewCourse=Course(NewCourseNo,NewCourseName,NewCoursePrice)##新创建的对象直接实例化
courses_dict={"CourseNo":NewCourseNo,"CourseName":NewCourseName,"CoursePrice":NewCoursePrice}#用字典来存放讲师信息
ifnotdic:
dic[NewCourseNo]=courses_dict
json.dump(dic,open("course_db","w"),encoding='utf-8',ensure_ascii=False,indent=2)
else:
ifdic.get(NewCourseNo):
print("%s课程已存在,不能注册课程号相同的课程"%NewCourseNo)
else:
dic[NewCourseNo]=courses_dict
json.dump(dic,open("course_db","w"),encoding='utf-8',ensure_ascii=False,indent=2)
print("Coursehasalreadycreatedsuccessfully".center(50,'-'))
print("""
CourseNo:%s
CourseName:%s
CoursePrice:%s"""%(NewCourseNo,NewCourseName,NewCoursePrice))

classTeacher(object):
def__init__(self,TeacherName,TeacherAge,TeacherSex,CourseNo,Salary):
self.TeacherName=TeacherName
self.TeacherAge=TeacherAge
self.TeacherSex=TeacherSex
self.CourseNo=CourseNo
self.Salary=Salary

defTeachKnowledge(self):
print"TeachKnowlege~"

defTeacherInfo(self):
print("""
-------------讲师信息-------------
Name:%s
Age:%s
Sex:%s
CourseNo:%s
Salary:%s
"""%(self.TeacherName,self.TeacherAge,self.TeacherSex,self.CourseNo,self.Salary))
##课程类定义
classCourse(object):
def__init__(self,CourseNo,CourseName,CoursePrice):
self.CourseNo=CourseNo
self.CourseName=CourseName
self.CoursePrice=CoursePrice
defShowCourseInfo(self):
print("""
CourseNO:%s
CourseName:%s
CoursePrice:%s"""%(self.CourseNo,self.CourseName,self.CoursePrice))
##学员类定义
classStu(object):
def__init__(self,StuName,StuAge,StuSex,StuSchool,CourseNo,StuID,CoursePrice):
self.StuName=StuName
self.StuAge=StuAge
self.StuSex=StuSex
self.StuSchool=StuSchool
self.CourseNo=CourseNo
self.StuID=StuID
self.CoursePrice=CoursePrice
defStudy(self):
print"study"
defPayMoney(self):
print"Payingformoney~"
defStuInfo(self):
print("""
---------------学生信息--------------
Name:%s
Age:%s
Sex:%s
School:%s
CourseNo:%s
ID:%s
CoursePrice:%s
"""%(self.StuName,self.StuAge,self.StuSex,self.StuSchool,self.CourseNo,self.StuID,self.CoursePrice))

defstudents_view():#学员视图
whileTrue:
pro="""
1.欢迎注册
2.返回
3.退出

请选择:
"""
num=raw_input(pro)
ifnum=='1':
choice_school_obj.RecruitStu()#调用学生注册方法并生成学生对象
elifnum=='2':
break
elifnum=='3':
sys.exit()
else:
continue

defteacher_view():#讲师视图
name=raw_input("请输入讲师姓名:")
whileTrue:
ifdic.get(name)orteachers_dict.get(name):
print("欢迎%s讲师".center(50,'-')%name)
elifnotdic.get(name)andnotteachers_dict.get(name):
print("%s讲师不存在"%name)
break
pro="""
1.查看学员信息
2.返回
3.退出

请输入你的选择:
"""
num=raw_input(pro)
ifnum=='1':
ifteachers_dict.get(name):
teachers_dict[name].show_student()#查看学生信息
else:
print("功能未完善,只能输入lvah,cheng")
elifnum=='2':
break
elifnum=='3':
sys.exit()
else:
continue

defschool_view():#学校视图
whileTrue:
pro="""
1.创建课程
2.招生注册
3.聘用讲师
4.返回
5.退出

请输入你的选择:
"""
num=raw_input(pro)
ifnum=='1':
choice_school_obj.CreateCourse()
elifnum=='2':
choice_school_obj.RecruitStu()
elifnum=='3':
choice_school_obj.HireTch()
elifnum=='4':
break
elifnum=='5':
sys.exit()
else:
continue

defmain():
globaldic#全局变量
globalchoice_school_obj
dic={}

whileTrue:
print("请选择学校".center(50,'*'))
pro1="""
1.%s
2.%s
3.返回
4.退出

请输入你的选择:
"""%(school1.SchoolName,school2.SchoolName)
choice_school=raw_input(pro1)
ifchoice_school=='1':
choice_school_obj=school1#将对象引用传给choice_school
elifchoice_school=='2':
choice_school_obj=school2
elifchoice_school=='3':
break
elifchoice_school=='4':
sys.exit()
else:
continue
whileTrue:
print("请选择视图".center(50,'*'))
pro2="""
1.学员视图
2.讲师视图
3.学校管理视图
4.返回
5.退出

请选择视图:
"""

num=raw_input(pro2)

ifnum=='1':
print("欢迎进入学员视图".center(50,'*'))
students_view()
elifnum=='2':
print("欢迎进入讲师视图".center(50,'*'))
teacher_view()
elifnum=='3':
print("欢迎进入学校管理视图".center(50,'*'))
school_view()
elifnum=='4':
break
elifnum=='5':
sys.exit()
else:
continue

if__name__=='__main__':

teachers_dict={}
courses_dict={}
stus_dict={}

school1=School("A大学","曲江校区","祖国、荣誉、责任")#实例化两个学校
school2=School("B大学","长安区","爱国、求是、奋进")

t1=Teacher("leo","28","male","01","10000")
t2=Teacher("harry","26","female","02","9000")#实例化两个讲师
teachers_dict["leo"]=t1
teachers_dict["harry"]=t2
teacher_dict={"TeacherName":"leo","TeacherAge":"28","TeacherSex":"male","CourseNo":"01","Salary":"10000"}
teacher_dict={"TeacherName":"harry","TeacherAge":"26","TeacherSex":"female","CourseNo":"02","Salary":"9000"}

course1=Course("01","Linux云自动化运维","12800")#实例化两个课程
course2=Course("02","c/c++开发","9800")
courses_dict["01"]=course1
courses_dict["02"]=course2
courses_dict={"CourseNo":"01","CourseName":"Linux云自动化运维","CoursePrice":"12800"}
courses_dict={"CourseNo":"02","CourseName":"c/c++开发","CoursePrice":"9800"}

stu1=Stu("Katy","18","female","A大学","01","3150911026","12800")##实例化两个学员
stu2=Stu("Betty","18","male","B大学","02","3150911022","12000")
stus_dict["Katy"]=stu1
stus_dict["Betty"]=stu2
stu_dict={"StuName":"Katy","StuAge":"18","StuSex":"female","StuSchool":"A大学","CourseNo":"01","StuID":"3150911026","CoursePrice":"12800"}
stu_dict={"StuName":"Betty","StuAge":"18","StuSex":"male","StuSchool":"B大学","CourseNo":"02","StuID":"3150911022","CoursePrice":"12000"}
print(school1,school2)
main()

三、运行结果

Python如何实现学校管理系统

Python如何实现学校管理系统

感谢你能够认真阅读完这篇文章,希望小编分享的“Python如何实现学校管理系统”这篇文章对大家有帮助,同时也希望大家多多支持恰卡编程网,关注恰卡编程网行业资讯频道,更多相关知识等着你来学习!

发布于 2021-03-24 01:19:57
收藏
分享
海报
0 条评论
164
上一篇:python怎么实现用户名密码校验 下一篇:python从ftp服务器下载文件的示例
目录

    推荐阅读

    0 条评论

    本站已关闭游客评论,请登录或者注册后再评论吧~

    忘记密码?

    图形验证码