# 选择职业
# 能登陆
# 能注册
# 能退出
# 能查已经报名的科目
# 能报名
import time
course_dict = {
'1': '高等数学',
'2': 'photoshop的使用',
'3': 'C语言的学习',
'4': '面向对象程序设计',
'5': '心理课',
'6': 'Unity游戏制作',
}
course_list = {}
id_dict = {
'1': 'student',
'2': 'teacher',
'3': 'administrator',
}
ids = '''
1:student
2:teacher
3:administrator
'''
username_list = []
def log_deco(func):
def wrapper(*args, **kwargs):
print(f"你是什么职业?{ids}")
clas = input("")
if clas not in id_dict:
print("你是什么东西?重输好吗?")
else:
global x
x=id_dict[clas]
res = func(*args, **kwargs)
return res
return wrapper
# print(x)
def inp_username_pwd():
username_inp = input('请输入你的用户名')
pwd_inp = input('请输入你的密码')
return username_inp, pwd_inp
@log_deco
def login():
print('欢迎来到登陆系统')
if username_list:
print("你已经登陆了哦,别再登陆了")
return
count = 0
while count < 3:
username_inp, pwd_inp = inp_username_pwd()
with open(f'{x}info.txt', 'r', encoding='utf8') as fr:
for use_info in fr:
use_info = use_info.strip()
username, pwd = use_info.split(':')
if username == username_inp and pwd == pwd_inp:
print("登陆中", end="")
for i in range(5):
print(".", end='')
time.sleep(0.2)
print(".")
print('成功登陆')
username_list.append(username_inp)
return
else:
print('由于一些原因,登陆失败了')
count += 1
@log_deco
def register():
print('欢迎来注册')
username_inp, pwd_inp = inp_username_pwd()
with open(f'{x}info.txt', 'a', encoding='utf8')as fa:
fa.write(f'{username_inp}:{pwd_inp}
')
def check():
if not username_list:
print("请登陆之后再来哦")
return
print('欢迎来看报名情况呀')
print("正在进入选课查看", end="")
for i in range(5):
print(".", end='')
time.sleep(0.2)
print(".")
with open('choosed_course', 'r', encoding='utf8')as fr:
data = fr.read()
print(data)
print('
')
def report():
print("你来选课啦!要选两门课哦!")
if not username_list:
print("请登陆之后再来哦")
return
print('''
1.高等数学
2.photoshop的使用
3.C语言的学习
4.面向对象程序设计
5.心理课
6.Unity游戏制作
''')
choose_count = 0
while choose_count < 2:
course_choice = input("请输入你想要选择的科目的数字")
if course_choice not in course_dict:
print('请输入列表里有的科目哦')
continue
course_name = course_dict[course_choice]
if course_name in course_list:
course_list[course_name] += 1
choose_count += 1
else:
course_list[course_name] = 1
choose_count += 1
print(f'成功选择{course_name},你一共选择了{course_list}')
with open('choosed_course', 'a', encoding='utf8')as fa:
fa.write(f'{username_list}:{course_name}
')
func_dice = {
'1': login,
'2': register,
'3': check,
'4': report,
}
while True:
print('''
1 登陆
2 注册
3 查看报了啥
4 选课
q 退出
''')
func_choice = input('请输入你想要进行的操作(输入q退出):')
if func_choice == 'q':
print("正在退出", end="")
for i in range(5):
print(".", end='')
time.sleep(0.2)
print(".")
break
if func_choice not in func_dice:
print("你看不懂中国字吗")
continue
func_dice[func_choice]()