小程序之用户管理系统

       写一个小程序实现用户的管理,即用户注册,用户登录,用户信息显示,用户注销


#coding:utf-8

print """
    1.注册新用户
    2.登录用户
    3.显示用户信息
    4.注销用户
    5.退出
"""

info = {
    'user1': {
        'name': 'user1',
        'password': '123',
        'gender': '0',  ##0-male,1-female,2-others,
        'email': '[email protected]',
        'age': '14'
    }
}

def createUser():
    print "注册新用户".center(40, "*")
    username = raw_input("username:")
    if username in info:
        print "用户已存在"
    else:
        password = raw_input("password:"),
        gender = input("gender(0-male,1-female,2-other):"),
        email = raw_input("email:"),
        age = input("age:")
        info[username] = {
            'name': username,
            'password': password,
            'genter': genter,
            'email': email,
            'age': age,
        }
        print "%s 注册成功" % (username)

def login():
    print "用户登录".center(40, "*")
    i = 0
    while i < 3:
        inname = raw_input("username:")
        if not inname in info:
            print "用户未注册"
            break
        inpassword = raw_input("password:")
        if inpassword == info[inname]['password']:
            print "登陆成功"
            exit()
        else:
            print "登录失败"
            break             ##退出异常
        i += 1
    else:
        print "登陆超过三次,请稍后登陆"

def showUser():
    print "显示用户信息".center(40, "*")
    inname = raw_input("username:")
    if inname in info:
        for inname in info:
            print info[inname]
    else:
        print "该用户不存在"

def delUser():
    inname = raw_input("username:")
    if not inname in info:
        print "用户未注册"
    else:
        inpassword = raw_input("password:")
        if inpassword == info[inname]['password']:
            info.pop("inname")
        print "该用户已注销!"

while True:
    choice = raw_input("你的选择:")
    if choice == "1":
        ##注册新用户
        createUser()
    elif choice == "2":
        ##登录用户
        login()
    elif choice == "3":
        ##显示用户信息
        showUser()
    elif choice == "4":
        ##注销用户
        delUser()
    elif choice == "5":
        ##退出
        exit()
    else:
        print " 请输入合法选择!"

你可能感兴趣的:(小程序之用户管理系统)