python寫的簡單的選課系統,遇到一堆問題
寫了一個簡單的選課系統的程式碼,問題一堆,遇到pickle反序列化不能完全匯出的問題,大神還煩解答下吧
#!/bin/bash/evn python
#* coding:utf-8 *
#Autior Dahai
import pickle
‘’‘定義三個函式,建立班級,建立課程和建立老師’’’
def creat_class():
classes_creat_name = input("請輸入班級的姓名:")
with open("classes_creat.txt",'ab') as f:
f.write(pickle.dumps(classes_creat_name))
def creat_course():
course_creat_name = input(“請輸入課程名稱:”)
with open(“course_creat.txt”,‘ab’) as f:
f.write(pickle.dumps(course_creat_name))
def creat_teachers():
teachers_creat_name = input("請輸入老師姓名:")
teachers_creat_passwd=input("請輸入密碼---->>>")
teachers_creat_info={teachers_creat_name:teachers_creat_passwd}
with open("teachers_creat.txt",'ab') as f:
f.write(pickle.dumps(teachers_creat_info))
‘’‘現有班級情況’’’
classes_python=[‘python精品班14期’,‘python衝刺班14期’,‘python基礎班14期’]
classes_linux=[‘linux精品班14期’,‘linux衝刺班14期’,‘linux基礎班14期’]
classes_go=[‘go精品班14期’,‘go衝刺班14期’,‘go基礎班14期’]
‘’‘初始化班級’’’
def initialize_class():
with open(“course_creat.txt”,‘wb’) as f:
f.write(pickle.dumps(classes_python))
f.write(pickle.dumps(classes_linux))
f.write(pickle.dumps(classes_go))
‘’‘定義初始化函式,初始化後課程迴歸到剛開始狀態’’’
def initialize():
with open(“classes_creat.txt”,‘wb’)as f:
f.write(pickle.dumps(classes_python))
f.write(pickle.dumps(classes_linux))
f.write(pickle.dumps(classes_go))
print("系統初始化已完成")
‘’‘定義學校’’’
class School(object):
def init(self,name,addr):
self.name=name
self.addr=addr
course_name=[]
classes_name=[]
teachers_name=[]
def tell(self):
print('''
-------info of %s--------
school name:%s
school address:%s
school teaching:IT'''%(self.name,self.name,self.addr))
school1=School(‘老男孩教育’,‘北京天安門’)
school2=School(‘老男孩教育’,‘上海南京路’)
‘’‘定義班級’’’
class Clesses(School):
def index(self,name,addr,course_name,teachers_name):
super(Clesses, self).index(course_name,teachers_name)
def tell(self):
print(’’’
-------info of %s--------
classes name:%s
classes course:%s
classes teacher:%s
classes address:%s’’’ % (self.name, self.name, self.course_name,self.teachers_name,self.addr))
‘’‘定義課程’’’
class Course(object):
def init(self,name,period,cost,addr):
self.name=name
self.period=period
self.cost=cost
self.addr=addr
def tell(self):
print('''
-------info of %s--------
course name:%s
course period:%s
classes cost:%s
classes address:%s''' % (self.name, self.name, self.period, self.cost,self.addr))
python=Course(‘python14期’,‘8個月’,12000,‘北京’)
linux=Course(‘linux13期’,‘6個月’,10000,‘北京’)
go=Course(‘go8期’,‘5個月’,9000,‘上海’)
‘’‘定義學生註冊函式’’’
def enroll():
print(’--------歡迎進入學員註冊介面--------’)
name = input(“請輸入你的姓名”)
age = input(“請輸入你的年齡”)
sex = input(“請輸入你的性別”)
passwd = input(“請輸入你的密碼”)
date1=[name,age,sex,passwd]
with open(“學員資訊.txt”, ‘ab’) as f:
f.write(pickle.dumps(date1))
‘’‘定義學生這個類:可以選擇課程和班級’’’
class Student(object):
def init(self,name,age,sex):
self.name=name
self.age=age
self.sex=sex
self.course = []
self.classes=[]
def tell(self):
print('''
-------info of %s--------
student name:%s
student age:%s
student sex:%s
student course:%s
student classes:%s''' % (self.name, self.name, self.age, self.sex, self.course,self.classes))
def choice_course(self): #進入學生選課函式
print(school1.tell(), school2.tell())
student_school_choice = input("請選擇學校名")
print("1-->")
python.tell()
print("2-->")
linux.tell()
print("3-->")
go.tell()
choice_name=input("請選擇課程,輸入對應編號")
money=int(input('請輸入金額'))
if money == 12000:
with open("classes_creat.txt", 'rb') as f:
date = pickle.loads(f.readline())
print(date)
choice_classes = input("請選擇班級")
with open("學員課表.txt", 'ab') as f:
f.write(pickle.dumps(choice_classes))
f.write(pickle.dumps('\npython課程\n'))
elif money == 10000:
with open("classes_creat.txt", 'rb') as f:
date = pickle.loads(f.readline())
print(date)
choice_classes = input("請選擇班級")
self.course.append('linux')
self.classes = [choice_classes]
with open("學員課表.txt", 'ab') as f:
f.write(pickle.dumps(choice_classes))
f.write(pickle.dumps(self.course))
elif money == 9000:
with open("classes_creat.txt", 'rb') as f:
date = pickle.loads(f.readline())
print(date)
choice_classes = input("請選擇班級")
self.course.append('go')
self.classes = [choice_classes]
with open("學員課表.txt", 'ab') as f:
f.write(pickle.dumps(choice_classes))
f.write(pickle.dumps(self.course))
with open("學員資訊.txt", 'ab') as f:
f.write(pickle.dumps(student_school_choice))
print("恭喜您報名成功")
initialize()
st1=Student(‘zhansan’,25,‘man’)
st1.choice_course()
‘’‘主程式入口’’’
view={1:“管理員入口”,
2:“老師入口”,
3:“學生入口”}
print("-----------歡迎進入老男孩課程系統-----------")
while True:
print(“系統視窗如下:”)
print(view)
import_in=int(input("請選擇系統視窗編號:----->>>"))
if import_in==1:
admin=input("請輸入管理員賬號---->>>")
passwd=input("請輸入管理員密碼---->>>")
if passwd=='abc123':
view_admin={1:"建立班級",
2:"建立老師",
3:"建立課程",
4:"檢視學員資訊",
5:"初始化班級"}
print("歡迎進入管理介面")
print(view_admin)
admin_choice=int(input("------請選擇操作編號---->>>>"))
if admin_choice==1:
creat_class()
elif admin_choice==2:
creat_teachers()
elif admin_choice==3:
creat_course()
elif admin_choice==4:
with open("學員資訊.txt",'rb') as f: ###後面補充學員資訊情況
date2=pickle.loads(f.read())
print(date2)
elif admin_choice==5:
ok=input("此操作有風險,是否確認操作y/n:---->")
if ok=="y":
initialize()
initialize_class() ###初始化函式
else:
print("謝謝使用")
pass
#寫程式時再加入主變數
elif import_in==2:
with open("teachers_creat.txt", 'rb') as f:
date=pickle.loads(f.readline())
teacher_admin=input("請輸入賬號---->>")
teacher_passwd=input("請輸入密碼---->>")
if teacher_passwd==date[teacher_admin]:
view_teacher={1:"檢視班級資訊",
2:"檢視班級學員列表",
3:"修改密碼"}
print("---------歡迎進入教師入口--------")
print(view_teacher)
teacher_choice=int(input("請選擇操作編號----->>>"))
if teacher_choice==1:
with open("course_creat.txt",'rb')as f:
info_ok=[]
for info in pickle.loads(f.read()):
info_ok.append(info)
print(info_ok)
elif teacher_choice==2:
pass ##建立完學員資訊後補全
elif teacher_choice==3:
pass
elif import_in==3:
enroll()
with open("學員資訊.txt", 'rb') as f:
stu1_info=pickle.loads(f.readline())
student1=Student(stu1_info[0],stu1_info[1],stu1_info[2])
student1.choice_course()