python课程典范选优_python学生选课系统

#登录

importsysimportosfrom core importauthfrom conf importsettingsimportpickleimporthashlibdef md5(arg): #这是加密函数,将传进来的函数加密

md5_pwd = hashlib.md5(bytes('123', encoding='utf-8'))

md5_pwd.update(bytes(arg, encoding='utf-8'))return md5_pwd.hexdigest() #返回加密的数据

classDie:defshow_select_courese(self):

with open(settings.courseinfo,'rb') as f:whileTrue:try:

obj=pickle.load(f)print('课程名字:%s,课程价格:%s,课程周期:%s,教导老师:%s' %(obj.name, obj.price, obj.period, obj.tearch))exceptEOFError:break

classCourse:def __init__(self,name,price,period,tearch):

self.name=name

self.price=price

self.period=period

self.tearch=tearchclassStudent:

operat_list= [('查看可选课程','show_courese'),('选择课程','choose_course'),('查看已选课程','show_select_courese'),('退出','exit')]

courses_list1=[]def __init__(self,name):

self.name=namedefshow_courese(self):

Die.show_select_courese(self.name)defchoose_course(self):

Die.show_select_courese(self.name)

with open(settings.select_course,'ab') as f1:

cours= input('请选择要学习课程名字:')if cours inStudent.courses_list1:print('课程已存在')else:

Student.courses_list1.append(cours)

pickle.dump({self.name: Student.courses_list1}, f1)print('用户%s,添加课程%s成功' %(self.name, cours))#pickle.dump({ret['user']:Student.courses_list1},f1)

#print('用户%s,添加课程%s成功'%(ret['user'],cours))

defshow_select_courese(self):

with open(settings.select_course,'rb') as f1:whileTrue:try:

obj=pickle.load(f1)print(obj)exceptEOFError:break

defexit(self):

exit('欢迎再来')classManager(Die):

operat_list= [('创建课程', 'create_course'),

('创建学生', 'create_student'),

('查看可选课程', 'show_select_course'),

('查看所有学生', 'show_select_student'),

('查看所有学生和已选课程', 'show_stu_course'),

('创建讲师', 'create_tearch'),

('为讲师指定班级', 'tearch_grade'),

('创建班级', 'create_grade'),

('为学生指定班级', 'select_stu_grade'),

('退出', 'exit')]def __init__(self,name):

self.name=namedefcreate_course(self):

name= input('请输入课程:')

price= input('价格:')

period= input('周期:')

tearch= input('tearch:')

course=Course(name,price,period,tearch)

with open(settings.courseinfo,'ab') as f:

pickle.dump(course,f)print('课程创建成功')defcreate_student(self):

user= input('请输入创建的学生名字:')

pwd= input('请输入密码:')

ret= input('输入学生的类别,例如Student:')if ret == 'Student':

course= '\n%s|%s|%s'%(user,md5(pwd),ret)

with open(settings.userinfo,'a') as f:

f.write('%s'%course)print('%s创建成功'%user)else:print('您输入的不是Student')defshow_select_course(self):

Die.show_select_courese(self.name)defshow_select_student(self):

with open(settings.userinfo,'r') as f:for i inf:

name,pwd,identify= i.strip().split('|')if identify == 'Manager' or identify == 'Tearch':pass

else:print(name)defshow_stu_course(self):

with open(settings.select_course,'rb') as f1:whileTrue:try:

obj=pickle.load(f1)for x,y inobj.items():print('用户%s一共学习了%s课程'%(x,y))#print(obj)

exceptEOFError:break

defcreate_tearch(self):

user= input('请输入创建的讲师名字:')

pwd= input('请输入密码:')

ret= input('输入讲师的类别,例如Tearch:')if ret == 'Tearch':

course= '\n%s|%s|%s'%(user,md5(pwd),ret)

with open(settings.userinfo,'a') as f:

f.write('%s'%course)print('%s老师创建成功'%user)else:print('您输入的不是Student')deftearch_grade(self):

grade_list=[]

with open(settings.userinfo,'r') as f:for line inf:

name,pwd,identify= line.strip().split('|')

with open(settings.gradeinfo,'rb') as f1:

obj=pickle.load(f1)

grade_list.append(obj)if identify == 'Tearch':print('可以为%s老师分配班级有\n(%s)班'%(name,obj))print('-------------')

grade= int(input('请输入班级号'))

with open(settings.tearch_grade,'ab') as f2:

pickle.dump({name:grade_list},f2)print('%s老师已经为%s班的讲师'%(name,grade))defcreate_grade(self):

grade= input('请输入您要创建的班级号')

with open(settings.gradeinfo,'ab') as f:

pickle.dump(grade,f)print('%s号班级已经创建成功'%grade)defselect_stu_grade(self):

stu_grade=[]

with open(settings.userinfo,'r') as f:

with open(settings.gradeinfo,'rb') as f1:

obj=pickle.load(f1)for line inf:

name, pwd, identify= line.strip().split('|')if identify == 'Manager' or identify == 'Tearch':pass

else:print('请为下面(%s)学生选择班级,\n可选班级有(%s)号班级\n'%(name,obj))

ret= input('请输入要选择的班级号')#stu_grade.append('ret')

with open(settings.student_grade,'ab') as f3:

pickle.dump({name:ret},f3)print('学生%s已经加入到%s班级'%(name,ret))defexit(self):

exit('欢迎下次再来')classTearch(Die):

operat_list= [('查看所有课程', 'select_course'),

('查看所教班级', 'select_grade'),

('查看班级中学生', 'select_grade_stu'),

('退出', 'exit')]def __init__(self,name):

self.name=namedefselect_course(self):

Die.show_select_courese(self.name)defselect_grade(self):

with open(settings.tearch_grade,'rb') as f:

obj=pickle.load(f)for x,y inobj.items():print('%s老师交的班级有%s'%(x,y))defselect_grade_stu(self):

with open(settings.student_grade,'rb') as f:

obj=pickle.load(f)for x,y inobj.items():print('%s号班级里一共有%s位学生'%(y,x))defstart():

ret=auth.login()if ret['identify']:

cls= getattr(sys.modules[__name__],ret['identify'])

obj= cls(ret['user'])whileTrue:for index,i in enumerate(cls.operat_list,1):print(index,i[0])

ind= int(input('please num'))print('----------------')

func= cls.operat_list[ind-1][1]

getattr(obj,func)()print('----------------')

本文链接:https://my.lmcjl.com/post/3909.html

展开阅读全文

4 评论

留下您的评论.