登录注册系统
"""__author__ = iwsyt"""
import time
def begin_interface():
print('☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆')
print(' ★欢迎来到学生管理系统★ ')
print()
print(' ※1、登 录 ')
print(' ※2、注 册 ')
print(' ※3、退 出 ')
print()
print('☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆')
def register():
while True:
user_name = input('User Name:')
first_char = user_name[0]
name_length = len(user_name)
if 'a' <= first_char <= 'z' or 'A' <= first_char <= 'Z':
if 5 <= name_length <= 13:
for char in user_name[1:]:
if not 'a' <= char <= 'z' or 'A' <= char <= 'Z' or '0' <= char <= '9':
print('账号名必须由字母和数字组成!')
time.sleep(1)
break
else:
with open('users_list.txt', 'r', encoding='utf-8') as f:
users = eval(f.read())
for key in users:
if key == user_name:
print('该用户已注册!请重新输入!')
time.sleep(1)
break
else:
password = input('Password:')
users[user_name] = password
with open('users_list.txt', 'w', encoding='utf-8') as f:
f.write(str(users))
print('恭喜你注册成功!')
time.sleep(1)
break
else:
print('账号名长度必须为5-13位!')
time.sleep(1)
else:
print('账号名开头必须为字母!')
time.sleep(1)
def login():
while True:
user_name = input('User Name:')
password = input('Password:')
with open('users_list.txt', 'r', encoding='utf-8') as f:
users = eval(f.read())
if user_name in users:
if users[user_name] == password:
print('登陆成功!')
break
else:
print('密码错误!请重新输入!')
else:
print('该用户未注册,请注册后再登录!')
def main_interface():
names = []
ages = []
phones = []
while True:
print('\n☆☆☆欢迎进入学生管理系统!☆☆☆\n')
print('1.添加学生\n2.查看学生信息\n3.修改学生信息\n4.删除学生信息\n5.退出\n')
print('☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆')
button = int(input('\n请选择功能:'))
key = 1
if button == 1:
while key == 1:
names.append(input('\n学生名字:'))
ages.append(input('学生年龄:'))
phones.append(input('联系方式:'))
print('\n添加成功!\n1.继续\n2.返回')
key = int(input('\n请选择功能:'))
elif button == 2:
if names:
print('\n序号 姓名 年龄 联系方式')
for index in range(len(names)):
print(index+1, ' ', names[index], ' ', ages[index], ' ', phones[index])
else:
print('暂无学生信息,请返回添加后再操作!')
print('\n1.返回')
# button = int(input('\n请选择功能:'))
elif button == 3:
while key == 1:
print('\n序号 姓名 年龄 联系方式')
for index in range(len(names)):
print(index + 1, ' ', names[index], ' ', ages[index], ' ', phones[index])
index = int(input('\n请输入想要修改的序号:')) - 1
print('\n1.姓名\n2.年龄\n3.联系方式')
button = int(input('\n请输入想要修改的项目:'))
if button == 1:
print(names[index], end='')
names[index] = input(' → ')
elif button == 2:
print(ages[index], end='')
ages[index] = input(' → ')
elif button == 3:
print(phones[index], end='')
phones[index] = input(' → ')
print('\n修改成功!\n1.继续修改\n2.返回')
key = int(input('\n请选择功能:'))
elif button == 4:
while key == 1:
print('\n序号 姓名 年龄 联系方式')
for index in range(len(names)):
print(index + 1, ' ', names[index], ' ', ages[index], ' ', phones[index])
index = int(input('\n请输入序号删除对应学生信息:')) - 1
del names[index], ages[index], phones[index]
print('\n删除成功!\n\n1.继续删除\n2.返回')
key = int(input('\n请选择功能:'))
elif button == 5:
print('已退出!')
break
else:
print('请输入1-5的数')
def main():
while True:
begin_interface()
value = int(input('请选择功能:'))
if value == 1:
login()
main_interface()
elif value == 2:
register()
elif value == 3:
break
if __name__ == '__main__':
main()