python练习4

题目1:用户管理系统V2:

用户功能如下:
welcome to xxxx system

  • 1.注册:若用户存在,直接报错”name 已经存在”,若用户不存在,将用户信息保存起来,显示”注册成功”;
  • 2.登陆:若用户存在,判断密码是否正确,若用户不存在,报错”name 不存在”;
  • 3.注销:若用户存在,删除用户信息;若不存在,报错报错”name 不存在;
  • 4.退出:break
#!/usr/bin/env python
#coding:utf-8
"""
file:login.py
date:2017-09-02 9:20 PM
author:lihang
desc:

"""
d = {"root":"westos"}


def add():
    username = raw_input('username:')
    if d.has_key(username):
        print "%s 已经存在!" % (username)
    else:
        password = raw_input('password:')
        d[username] = password
        print "%s 注册成功!" % (username)


def info():
    print "用户名\t密码"
    for username, password in d.items():
        print "%s\t%s" % (username, password)


def login():
    trycount = 0
    while True:
        if trycount == 3:
            print "登陆超过三次,再会,我的朋友!"
            exit()
        username = raw_input("username:")
        if not d.has_key(username):
            print "用户不存在!"
            break
        password = raw_input("password:")
        if d[username] == password:
            print "登陆成功!"
            exit()
        else:
            print "密码错误!"
        trycount += 1


def logout():
    username = raw_input("username:")
    if not d.has_key(username):
        print "用户不存在!"
    del (d[username])


while True:
    print """
    欢迎进入用户信息管理界面

        登陆:login(L)
        注册:add(A)
        注销:logout(O)
        显示:info(I)
        退出:quit(Q)
"""
    choice = raw_input("请输入你的选择:")
    if choice in 'lL':
        login()
        continue
    elif choice in 'aA':
        add()
        continue
    elif choice in 'oO':
        logout()
        continue
    elif choice in 'iI':
        info()
        continue
    else:
        exit()

题目2:用户管理系统V3:
d = {“name”:[]}

初始化有一个系统管理员:
用户分为两种:
用户登录:
- 登陆
- 退出

判断用户类型:
系统管理员功能:
- 1.添加用户
- 4.查看所有用户信息
- 5.退出:
普通用户功能:
- 1.查看个人信息
- 2.注销
- 2.退出

要求:
1. 根据用户身份,进入不同的管理界面;
2. 系统初始化一个系统管理员帐号;
3. 只有系统管理员可以添加用户和查看用户所有信息;
4. 普通用户只能查看个人信息,和注销帐号;

welcome to xxx system

- 1.注册:
- 2.登陆:
- 3.注销:
- 4.查看所有用户信息
- 5.退出:

#!/usr/bin/env python
#coding:utf-8
"""
file:login2.py
date:2017-09-02 9:27 PM
author:lihang
desc:

"""
d = {
    "root":"westos",
    "kiosk":"redhat",
}


def add():
    username = raw_input('username:')
    if d.has_key(username):
        print "%s 已经存在!" % (username)
    else:
        password = raw_input('password:')
        d[username] = password
        print "%s 注册成功!" % (username)


def info():
    print "用户名\t密码"
    for username, password in d.items():
        print "%s\t%s" % (username, password)


def login():
    trycount = 0
    while True:
        if trycount == 3:
            print "登陆超过三次,再会,我的朋友!"
            exit()
        username = raw_input("username:")
        if not d.has_key(username):
            print "用户不存在!"
            break
        password = raw_input("password:")
        if d[username] == password:
            print "登陆成功!"
            exit()
        else:
            print "密码错误!"
        trycount += 1


def logout():
    username = raw_input("username:")
    if not d.has_key(username):
        print "用户不存在!"
    del (d[username])


while True:
    pro = """
    欢迎进入用户信息管理界面

        登陆:login(L)
        注册:add(A)
        注销:logout(O)
        显示:info(I)
        退出:quit(Q)
"""
    dict = {
            "L":login,
            "A":add,
            "O":logout,
            "I":info,
            "Q":quit,
    }
    while True:
        choice = raw_input(pro)
        dict.get(choice)()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值