python_字典应用-用户管理系统

用户管理系统

要求:

1.注册新用户
如果注册用户已经存在,则报错;
需要填写信息: 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!"
                                                                                                                                                                                                                                                                                                 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值