登陆和注册界面.py
# !/usr/bin/env/python
# .*. encoding:utf-8 -*-
import json
key_username = 'username'
key_password = 'password'
log_data={key_username: None, key_password: None}
Landing =False
#登陆
def log_in(username):
global Landing
try:
with open('./'+username+'.json','r',encoding='utf-8') as f:
content = json.load(f)
for cont in content:
if password ==cont['password']:
Landing = True
else:
print('密码错误')
except:
print('没有用户信息请注册')
#打印注册
def print_register():
global username,password
username = input('请输入你想要注册的用户名:')
if len(username) <= 0:
print('用户名不能为空,请重新输入:')
print_register()
elif len(username) > 10:
print('用户名被限制不能用,重新输入:')
print_register()
password = input('请输入登陆密码:')
#注册
def register():
global log_data,all_data
log_data = {key_username: username, key_password: password}
try:
with open('./'+username+'.json','r',encoding='utf-8') as f:
all_data=json.load(f)
except FileNotFoundError:
all_data=[]
all_data.append(log_data)
with open('./'+username+'.json','w',encoding='utf-8') as f:
json.dump(all_data,f)
print('注册成功,正在返回登陆界面')
#打印
def print_login():
print('==================')
print('1.进行登陆')
print('2.我是第一次我要注册')
print('3.退出')
#主程序
while True:
if Landing == True:
break
print_login()
choose =int(input('选择你要进行的操作'))
if choose == 1:
username = input('输入用户名:')
password = input('输入密码')
log_in(username)
if choose == 2:
print_register()
register()
if choose == 3:
print('正在退出...')
exit()
登陆成功自动跳转到学生管理系统
|
|
|
学生管理系统界面.py
import 学生管理登陆界面 as st
while True:
if st.Landing == True:
print('登陆成功')
break
st.print_login()
while True:
student_data = []
def printmenu():
print('——————————欢迎进入千峰学生管理系统——————————')
print('1.添加学生', end='\n' * 2)
print('2.查找学生', end='\n' * 2)
print('3.删除学生', end='\n' * 2)
print('4.更新学生', end='\n' * 2)
print('5.退出系统')
print('6.将所添加的数据保存到本地')
print('7.把本地文件数据读取出来')
print('————————————————————————————————', end='\n' * 2)
#添加学生信息
def add_stduent():
student_name = input('请输入学生姓名:')
student_age = input('请输入学生年龄:')
student_phone = input('请输入学生电话号码:')
new_dict = {}
new_dict['name'] = student_name
new_dict['age'] = student_age
new_dict['phone'] = student_phone
student_data.append(new_dict)
print('1.继续添加')
print('2.返回上一层')
choice = int(input(''))
if choice == 1:
add_stduent()
#查找学生信息
def look_stduent():
print('1.查看所有学生的信息')
print('2.根据序号查看学生信息')
print('3.返回上一层')
choice = int(input(''))
if choice == 1:
print('学生信息如下')
print('序号 姓名 年龄 电话号码 ')
i = 1
for temp in student_data:
print('%d %s %s %s'%(i,temp['name'],temp['age'],temp['phone']))
i += 1
if choice == 2:
student_number = int(input('请输入学生序号:'))
print('序号 姓名 年龄 电话号码 ')
print('%d %s %s %s' % (student_number, student_data[student_number-1]['name'],
student_data[student_number-1]['age'], student_data[student_number-1]['phone']))
#删除学生信息
def delete_student():
print('1.删除一个学生信息')
print('2.删除全部学生信息')
print('3.返回上一层')
choice = int(input(''))
if choice == 1:
delete_number = int(input('输入你要删除学生的序号:'))
del student_data[delete_number - 1]
if choice == 2:
student_data.clear()
#更新学生信息
def update_student():
print('1.更新学生信息')
print('2.返回上一层')
choice = int(input(''))
if choice == 1:
student_number = int(input('输入学生的序号:'))
new_name = input('请输入学生姓名:')
new_age = input('请输入学生年龄:')
new_phone = input('请输入学生电话号码:')
student_data[student_number-1]['name'] = new_name
student_data[student_number - 1]['age'] = new_age
student_data[student_number - 1]['phone'] = new_phone
#保存文件
def save_data(name=None):
name = input('你想要保存的文件名')
print(student_data)
with open('E:/'+name+'.txt','a',encoding='utf-8') as f:
f.write(str(student_data))
#读取文件
def read_data(name=None):
try:
name = input(('你想要读取的文件名'))
with open('E:/'+name+'.txt','r',encoding='utf-8') as f:
if f:
content = f.read()
print(content)
else:
print('本地数据没有内容')
except FileNotFoundError:
print('无本地文件,正在创建....')
with open('E:/'+name+'.txt','w',encoding='utf-8') as f:
f.write('')
#退出程序
def break_game():
break_game = input('请按回车退出系统:')
while break_game == '':
print('程序结束~~')
exit()
#主程序
def main():
while True:
printmenu()
number = int(input('请输入你想要进行的操作:'))
if number == 1:
add_stduent()
if number == 2:
look_stduent()
if number == 3:
delete_student()
if number == 4:
update_student()
if number == 5:
break_game()
if number == 6:
save_data()
if number == 7:
read_data()
if __name__ == '__main__':
main()
网友评论