用Python实现户注册信息管理系统
如有帮助,望采纳
userlist = []
list = []
class user:
def __init__(self,username,password):
self.name = username
self.password = password
count = 0
file = open("test.txt","r")
for line in file.readlines():
line = line.replace('\n','')
line = line.split(',')
list.append(line)
count += 1
file.close()
count = int(count / 2)
m = 0; n = 1
for i in range(count):
temp1 = list[m]
temp2 = list[n]
m += 2; n += 2
userlist.append(user(temp1,temp2))
def add():
newname = input('请输入新的用户名:')
i = 0
y = 0
while i < count:
if newname == ' '.join(userlist[i].name):
print('您输入的用户名已经使用,请重新添加用户!')
y = 1
break
i += 1
if y == 0:
newpassword = input('请输入新用户的登录密码:')
userlist.append(user(newname,newpassword))
count += 1
def save():
file = open("test.txt","w+")
i = 0
while i < count:
file.write(' '.join(userlist[i].name))
file.write('\n')
file.write(' '.join(userlist[i].password))
file.write('\n')
i += 1
file.close()
print('已成功保存用户信息')
def seek():
u = input('请输入要查找的用户名:')
i = 0
y = 0
while i < count:
if u == ' '.join(userlist[i].name):
print(u+'已注册')
print('请选择操作:')
print('1.修改用户')
print('2.删除用户')
seekchoice = int(input('请输入序号选择对应操作:'))
if seekchoice == 1:
newname = input('请输入新的用户名:')
newpassword = input('请输入新用户的登录密码:')
userlist[i].name = newname
userlist[i].password = newpassword
print('已成功修改用户!')
elif seekchoice == 2:
userlist.remove(userlist[i])
print('已成功删除用户!')
else:
print('您输入的信息有误!')
y = 1
break
i += 1
if y == 0:
print(u+'不存在!')
print('用户注册信息管理系统')
print('1.显示全部已注册用户')
print('2.查找/修改/删除用户信息')
print('3.添加新用户')
print('4.保存用户数据')
print('5.退出系统')
choose1 = int(input(print('请输入序号选择对应菜单:')))
while choose1 != 5:
if choose1 == 1:
c = 0;m = 0;n = 1
while c < count:
print(c+1,'.username=',' '.join(list[m]),' password=',' '.join(list[n]))
m += 2;n += 2;c += 1
choose2 = input('按住Enter键继续······')
if choose2 == '\n':
continue
elif choose1 == 2:
seek()
choose2 = input('按住Enter键继续······')
if choose2 == '\n':
continue
elif choose1 == 3:
add()
choose2 = input('按住Enter键继续······')
if choose2 == '\n':
continue
elif choose1 == 4:
save()
choose2 = input('按住Enter键继续······')
if choose2 == '\n':
continue
else:
print('您输入的信息有误!')
choose1 = int(input(print('请输入序号选择对应菜单:')))
if choose1 == 5:
print('谢谢使用,系统已退出!')