学生选课系统,初版

import pickle
class kech:
'''
课程的的名字,价格,时间周期,代课老师
'''
def __init__(self,courses,price,cycle,teacher):
self.Courses = courses
self.Price = price
self.Cycle = cycle
self.Teacher = teacher
class Xs:
'''
学生的名字
年龄,性别
'''
def __init__(self,name,grade):
self.Name = name
self.grade = grade
def selected(self):
with open("课程信息","rb")as f:
while True:
try:
zhmm = pickle.load(f)
yield zhmm
except EOFError:
return False
def xuzekc(self):
for i in self.selected():print(i.__dict__)
a = input("请输入课程名字 : ").strip()
for i in self.selected():
if i.Courses == a:
self.course = i.__dict__
with open("学生信息", "ab")as f:
pickle.dump(self, f)
print("选择成功")
def chakask(self):
with open("学生信息","rb")as f:
while True:
try:
zhmm = pickle.load(f)
yield zhmm
except EOFError:
return False
class Gly:
'''
1、创建课程
2、创建学生学生账号
3、查看所有课程
4、查看所有学生
5、查看所有学生的选课情况
6、退出程序
'''
def __init__(self,name):
self.name = name
def found(self):#1、创建课程
courses = input("请输入创建的课程 : ")
price = input("输入课程价格 : ")
cycle = input("请输入课程周期 : ")
teacher = input("请输入授课老师 : ")
a = kech(courses, price, cycle, teacher)
with open("课程信息","ab")as f:
pickle.dump(a,f)
print("%s课程创建成功"%(a.__dict__))
def Create_account(self):
Account1 = input("学生账号 : ")
Code = input("学生密码 : ")
name = input("学生姓名 : ")
grade = input("学生班级 : ")
with open("账号密码","ab")as f:
s = {"ID":"学生","账号":Account1,"密码":Code,"姓名":name,"班级":grade}
print(s,"\033[0;33m注册成功\033[0m")
pickle.dump(s,f)
def cksuoykc(self):
with open("课程信息","rb")as f:
while True:
try:
zhmm = pickle.load(f)
yield zhmm
except EOFError:
return False
def ckansuoyouxues(self):
for i in dqwenjian():
if i["ID"] == "学生":
print(i["姓名"],i["班级"])
def cksuoyouxsxk(self):
with open("学生信息","rb")as f:
while True:
try:
zhmm = pickle.load(f)
yield zhmm
except EOFError:
return False
def glyzc():#注册管理员
Account = input("\033[0;31mInput virus : \033[0m").strip()
Password= input("\033[0;31mSelect the virus : \033[0m").strip()
name = input("\033[0;31mName entry : \033[0m").strip()
with open("账号密码","ab")as f:
s = {"ID": "管理员", "账号": Account, "密码": Password,"姓名":name}
pickle.dump(s,f)
def dqwenjian():#打开文件进行读取
with open("账号密码","rb")as f:
while True:
try:
zhmm = pickle.load(f)
yield zhmm
except EOFError:
return False
def pad(zh,m_m):#判断输入账号密码是否存在
for i in dqwenjian():
if i["账号"] == zh and i["密码"] == m_m:
if i["ID"] == "管理员":
print("\033[0;32m Welcome administrator login\033[0m")
return i
else:
print("Welcome to")
return i
else:
print("\033[0;31m Wrong account or password\033[0m")
def guanly(xx): #管理员操作界面
while True:
print("\033[0;35m1、创建课程\n"
"2、创建学生学生账号\n"
"3、查看所有课程\n"
"4、查看所有学生\n"
"5、查看所有学生的选课情况\n"
"6、退出程序\033[0m")
name = Gly(xx["姓名"])
print("欢迎\033[0;31m%s\033[0m登录管理员界面!!!"%name.name)
num = input("选择你要执行的序号>>>").strip()
if num == "1":
name.found()
if num == "2":
name.Create_account()
if num == "3":
for i in name.cksuoykc():print("\033[0;36m",i.__dict__,"\033[0m")
if num == "4":
name.ckansuoyouxues()
if num == "5":
for i in name.cksuoyouxsxk():print(i.__dict__)
if num == "6":
return
def xueshen(xx):#学生操作界面
print("欢迎%s同学登录学生界面!!!" % xx["姓名"])
while True:
print("\033[0;35m1、查看所有课程\n"
"2、选择课程\n"
"3、查看所选课程\n"
"4、退出程序\033[0m")
xsxx =Xs(xx["姓名"],xx["班级"])
a =input("输入要执行的序号 : ")
if a == "1":
for i in xsxx.selected():print(i.__dict__)
if a == "2":
xsxx.xuzekc()
if a == "3":
for i in xsxx.chakask():
if i.Name == xsxx.Name:
print(i.__dict__)
if a == "4": return
while True:
zh = input("\033[1;32;40m账号>>>\033[0m").strip()
m_m = input("\033[1;32;40m密码>>>\033[0m").strip()
if zh =="Looking for virus" and m_m == "#@!@!#":
glyzc()
else:
xx =pad(zh,m_m)
if xx["ID"] == "管理员":
guanly(xx)
break
elif xx["ID"] == "学生":
xueshen(xx)
break
posted @ 2018-11-22 21:20  雨中含春  阅读(249)  评论(0编辑  收藏  举报