import pickle
class Course(object):
def __init__(self, name, price, period):
self.name = name
self.price = price
self.period = period
class Student(object):
def __init__(self, name):
self.name = name
self.classes = []
def show_courses(self):
pass
def choose_course(self):
pass
def show_selected(self):
pass
def exit(self):
pass
class Manager(object):
opt_list = [(‘创建课程‘, ‘create_course‘), (‘创建学生‘, ‘create_student‘),
(‘查看课程‘, ‘show_courses‘), (‘查看学生‘, ‘show_students‘),
(‘查看学生和已选课程‘, ‘show_stu_course‘), (‘退出‘, ‘exit‘)]
def __init__(self, name):
self.name = name
def create_course(self):
pass
def create_student(self):
user = input(‘usename: ‘)
pwd = ‘123456‘
stu = Student(user)
‘‘‘
???????????????????????????????????????????????????????????
重复创建问题
‘‘‘
with open(‘userInfo‘, mode=‘a‘, encoding=‘utf-8‘) as f:
print(f‘{user}|{pwd}|student‘, file=f)
with open(‘studentInfo‘, mode=‘ab‘) as f:
pickle.dump(stu, f)
print(f‘学生{user}创建成功‘)
‘‘‘
???????????????????????????????????????????????????????????
打log问题,***老师在***时间创建了学生***
‘‘‘
def show_courses(self):
pass
def show_students(self):
pass
def show_stu_course(self):
pass
def exit(self):
pass
def login():
‘‘‘
None
:return: 登陆成功,返回用户名和身份;否则,返回false
‘‘‘
username = input(‘username:‘)
password = input(‘password:‘)
with open(‘userinfo‘) as f:
for line in f:
user, pwd, ident = line.strip().split(‘|‘)
if username == user and password == pwd:
return username, ident
return False
ret = login()
if ret:
print(f‘登录成功,{ret[0]}欢迎使用选课系统‘)
if ret[1] == ‘manager‘:
m = Manager(ret[0])
for i, opt in enumerate(Manager.opt_list, 1):
print(i, opt[0])
num = int(input(‘您需要选择的操作:‘))
if hasattr(m, Manager.opt_list[num-1][1]):
getattr(m, Manager.opt_list[num-1][1])()
else:
print(‘登陆失败‘)
选课系统