Python -练习4

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

用户功能如下:
welcome to xxxx system

  • 1.注册:若用户存在,直接报错”name 已经存在”,若用户不存在,将用户信息保存起来,显示”注册成功”;
  • 2.登陆:若用户存在,判断密码是否正确,若用户不存在,报错”name 不存在”;
  • 3.注销:若用户存在,删除用户信息;若不存在,报错报错”name 不存在;
  • 4.退出:break

解答:

#!/usr/bin/env python
#coding:utf-8
'''
File:.py
date:9/2/17 10:30 AM
author:peak
descrip:
'''
def Choice1():
    Logname = raw_input("log name \t\t\t: ")
    Logpasswd = raw_input("log password \t\t: ")
    if Info.has_key(Logname):
        if Info.get(Logname) == Logpasswd:
            print "Log successed !\t\t"
        else:
            print "Password is wrong !\t\t"
    else:
        print "NO Such User ! \t\t"

def Choice2():
    for x, y in Info.items():
        print """
                                     {}        :          {}
                    """.format(x, y)

def Choice3():
    Addkey = raw_input("please input the name \t\t: ")
    if Info.has_key(Addkey):
        print "User Has exited"
    else:
        Addvalue = raw_input("please input the password \t: ")
        Info.update({Addkey: Addvalue})
        print "Successful Add User  \t\t: {}".format(Addkey)

def Choice4():
    Delkey = raw_input("Delete UserName \t: ")
    if Info.has_key(Delkey) == False:
        print "No Such User"
    else:
        Info.pop(Delkey)
        print "Successful Delete the user   :   {}".format(Delkey)


Info = {}
while 1 :
    print """
                                 Welcome To Log System

                              **1**    :          登陆
                              **2**    :          显示所有用户和密码
                              **3**    :          注册
                              **4**    :          注销
                              **5**    :          退出

    """
    Choice=input('please input your choice \t: ')
    if Choice == 5 :
        exit(0)
    elif Choice == 1 :
        Choice1()

    elif Choice == 2 :
        Choice2()

    elif Choice == 3 :
        Choice3()

    elif Choice == 4 :
        Choice4()

运行结果

这里写图片描述

这里写图片描述

这里写图片描述

题目2:用户管理系统V3:

d = {“name”:[]}

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

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

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

解答:

#!/usr/bin/env python
#coding:utf-8
'''
File:.py
date:9/2/17 4:20 PM
author:peak
descrip:
'''
Info={"admin":{'admin':'admin'},"user":{'peak':'redhat'}}


def Choice1():
    Logname = raw_input("log name \t\t\t: ")
    Logpasswd = raw_input("log password \t\t: ")
    if Info[a].has_key(Logname):
        if Info[a][Logname] == Logpasswd:
            print "Log successed !\t\t"
        else:
            print "Password is wrong !\t\t"
    else:
        print "NO Such User ! \t\t"


def Choice2():
    for x, y in Info[a].items():
        print """
                                     {}        :          {}
                    """.format(x, y)


def Choice3():
    Addkey = raw_input("please input the name \t\t: ")
    if Info.has_key(Addkey):
        print "User Has exited"
    else:
        Addvalue = raw_input("please input the password \t: ")
        Info.update({Addkey: Addvalue})
        print "Successful Add User  \t\t: {}".format(Addkey)


def Choice4():
    Delkey = raw_input("Delete UserName \t: ")
    if Info.has_key(Delkey) == False:
        print "No Such User"
    else:
        Info.pop(Delkey)
        print "Successful Delete the user   :   {}".format(Delkey)


def print0():
    print """
                                 Welcome To Log System

                              **1**    :          登陆
                              **2**    :          退出

        """
    global Choice
    Choice = input('please input your choice \t: ')
def print01():
    print """
                                 Welcome To Log System

                              **1**    :          管理员登陆
                              **2**    :          普通用户登陆
                              **3**    :          退出

        """
    global Choice
    Choice = input('please input your choice \t: ')
def print2():
    print """
                                 Welcome To CUSTOM Log System

                              **1**    :          查看个人信息
                              **2**    :          注销
                              **3**    :          退出

    """
    global Choice
    Choice = input('please input your choice \t: ')
def print1():
    print """
                                 Welcome To ADMIN Log System

                              **1**    :          添加用户
                              **2**    :          查看所有用户和密码
                              **3**    :          退出


        """
    global Choice
    Choice = input('please input your choice \t: ')

Choice = None
print0()
if Choice == 2:
    exit(0)
elif Choice == 1 :
    print01()
    if Choice == 1:
        a='admin'
        Choice1()
        print1()
        if Choice == 1:
            Choice3()
        if Choice == 2:
            Choice2()
        if Choice == 3:
            eixt()


    elif Choice ==2:
        a='user'
        Choice1()
        print2()
        if Choice == 1:
            Choice2()
        if Choice == 2:
            Choice4()
        if Choice == 3:
            eixt()


运行结果:

这里写图片描述

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值