1. 程式人生 > >簡易版學生選課系統

簡易版學生選課系統

登陸 :使用者輸入使用者名稱和密碼
  判斷身份 :在登陸成果的時候應該可以直接判斷出使用者的身份 是學生還是管理員
  學生使用者 :對於學生使用者來說,登陸之後有三個功能
       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+'
\n') 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'+'\n') 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)]+'\n') 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()