用户管理系统
要求:
如果注册用户已经存在,则报错;
需要填写信息: name, passwd, gender, email,age;
2.用户登录 要求同之前写的用户登录系统
3.注销用户 用户注销时,需要输入用户名和正确的用户密码
4.显示用户信息 显示系统中存在所有已经注册用户的信息;
5.退出系统
代码实现:
#!/usr/bin/env python
#coding:utf-8
info="""
用户管理系统
1)注册新用户
2)用户登陆
3)注销用户
4)显示用户信息
5)退出系统
请选择:
"""
user={}
news={}
count=0
while 1:
choice=raw_input(info)
if choice=="1":
name=raw_input("Name:")
if user.has_key(name):
print "user already exit!"
else:
password=raw_input("Password:")
gender=raw_input("Gender:")
email=raw_input("Email:")
age=raw_input("Age:")
#将用户信息储存
news.update(Password=password,Gender=gender,Email=email,Age=age)
user[name]=news
print "Registration Successful"
continue
elif choice=="2":
while count<3:
name=raw_input("Name:")
if user.has_key(name):
if password==raw_input("Password:"):
#查询用户密码是否与输入的密码一致
if password==user[name]["Password"]:
print "Log on Successful!"
break
else:
print "Incorrect password!"
count+=1
else:
print "Without this user"
break
elif choice=="3":
name=raw_input("Name:")
if user.has_key(name):
while 1:
if password==raw_input("Password:"):
if password==user[name]["Password"]:
del user[name]
print "Cancellation of success!"
break
else:
print "Incorrect password!"
count+=1
else:
print "Without this user"
elif choice=="4":
if not user:
print "No user!"
else:
print user
elif choice=="5":
exit()
else:
print "Reselection!"