登陆 :用户输入用户名和密码
判断身份 :在登陆成果的时候应该可以直接判断出用户的身份 是学生还是管理员
学生用户 :对于学生用户来说,登陆之后有三个功能
1、查看所有课程
2、选择课程
3、查看所选课程
4、退出程序
管理员用户:管理员用户除了可以做一些查看功能之外,还有很多创建工作
1、创建课程
2、创建学生学生账号
3、查看所有课程
4、查看所有学生
5、查看所有学生的选课情况
6、退出程序
1 class Admin: 2 def __init__(self,name): 3 self.name=name 4 def creat_course(self): 5 while 1: 6 name=input("请输入创建的课程(Q退出):").strip() 7 if name.upper()=='Q':break 8 with open('all_course','a+',encoding='utf-8') as f: 9 f.write(name+' ') 10 def creat_stu(self): 11 while 1: 12 stu=input("请输入创建的学生账号(Q退出):").strip() 13 if stu.upper() == 'Q': break 14 stu_pwd=input("请输入创建密码(Q退出):").strip() 15 if stu_pwd.upper() == 'Q': break 16 with open('userinfo', 'a+', encoding='utf-8') as f: 17 f.write(stu+'|'+stu_pwd+'|'+'student'+' ') 18 def show_course(self): 19 print("所有课程如下:") 20 with open('all_course',encoding='utf-8') as f: 21 for line in f: 22 print(line,end='') 23 def show_stu(self): 24 with open('userinfo', encoding='utf-8') as f: 25 for line in f: 26 lst=line.strip().split('|') 27 if lst[2]=='student': 28 print(lst[0]) 29 def check_course(self): 30 with open('course',encoding='utf-8')as f: 31 for line in f: 32 print(line,end='') 33 def exit(self): 34 exit() 35 36 class Student: 37 def __init__(self,name): 38 self.name=name 39 def show_course(self): 40 with open('all_course',encoding='utf-8') as f: 41 for line in f: 42 print(line,end='') 43 def choice(self): 44 while 1: 45 lst=[] 46 with open('all_course', encoding='utf-8') as f: 47 for line in f: 48 lst.append(line.strip()) 49 print(list(enumerate(lst,1))) 50 num=input("请输入要选择的课程序号(Q退出):") 51 if num.upper()=='Q':break 52 with open('course','a+',encoding='utf-8')as f: 53 f.write(self.name+'|'+lst[int(num)]+' ') 54 def check(self): 55 with open('course',encoding='utf-8')as f: 56 for line in f: 57 lst=line.strip().split('|') 58 if self.name==lst[0]: 59 print(line,end='') 60 def exit(self): 61 exit() 62 class Course: 63 def __init__(self,name,price,period,teacher): 64 self.name=name 65 self.price=price 66 self.period=period 67 self.teacher=teacher 68 69 def login(): 70 user=input("请输入用户名:").strip() 71 psd=input("请输入密码:").strip() 72 with open('userinfo','r',encoding='utf-8') as f: 73 for line in f: 74 if user+'|'+psd+'|'+'admin' == line.strip(): 75 return line 76 if user+'|'+psd+'|'+'student'==line.strip(): 77 return line 78 else:return False 79 80 def main(): 81 ret=login() 82 while ret: 83 if ret.strip().split('|')[2]=='admin': 84 print("欢迎进入管理员系统!" 85 "1.创建课程" 86 "2.创建学生学生账号" 87 "3.查看所有课程" 88 "4.查看所有学生" 89 "5.查看所有学生的选课情况" 90 "6.退出程序" 91 ) 92 num=input("请选择操作:") 93 user = ret.split('|')[0] 94 admin = Admin(user) 95 if num == '1': admin.creat_course() 96 if num == '2': admin.creat_stu() 97 if num == '3': admin.show_course() 98 if num == '4': admin.show_stu() 99 if num == '5': admin.check_course() 100 if num == '6': admin.exit() 101 elif ret.strip().split('|')[2]=='student': 102 print("欢迎进入学生系统!" 103 "1.查看所有课程" 104 "2.选择课程" 105 "3.查看所选课秤" 106 "4.退出程序" 107 ) 108 num =input("请选择操作:") 109 user = ret.split('|')[0] 110 student = Student(user) 111 if num == '1': student.show_course() 112 if num == '2': student.choice() 113 if num == '3': student.check() 114 if num == '4': student.exit() 115 else: 116 print("用户名或者密码错误!!!") 117 main()