用户管理系统

admin_info = {
    'root': 'redhat',
    'westos': 'westos'
}

user_info = {
    'sherry': 'lisongyan',
    'natasha': 'redhat'

}


def menu():
    print('用户管理系统登陆界面'.center(50, '`'))
    print("""
                1.我是管理员
                2.我是会员
                3.退出系统
    
    """)
    print('`' * 55)


def admin_login():
    for i in range(3):
        username = input('username:')
        passwd = input('password:')
        if username not in admin_info:
            print('用户名不存在。')
        else:
            if admin_info[username] == passwd:
                print('登陆成功。')
                admin_menu()
                break
            else:
                print('密码错误。')
    else:
        print('登陆错误超过三次请稍后再试。')


def admin_menu():
    while True:
        print('后台管理系统'.center(50, '`'))
        print("""
    
                    1.添加会员帐号
                    2.删除会员帐号
                    3.查看会员帐号信息
                    4.返回上层目录
                    5.退出
    
        """)
        print('`' * 55)
        choice = input('请输入服务序号:')
        if choice == '1':
            admin_add()
        elif choice == '2':
            admin_del()
        elif choice == '3':
            admin_check()
        elif choice == '4':
            break
        elif choice == '5':
            exit(0)
        else:
            print('非法输入。')


def admin_add():
    while True:
        name_add = input('username:')
        if name_add in user_info:
            print('用户名已存在。')
            continue
        else:
            while True:
                passwd_add = input('password:')
                passwd_add0 = input('repeat:')
                if passwd_add != passwd_add0:
                    print('两次输入密码不一致。')
                    continue
                else:
                    user_info[name_add] = passwd_add
                    print('会员添加成功。')
                    break
        break


def admin_del():
    while True:
        userdel = input('username:')
        if userdel not in user_info:
            print('用户不存在。')
            continue
        else:
            while True:
                choice = input('确认删除用户%s? y/n' % userdel)
                if choice == 'y':
                    del user_info[userdel]
                    print('删除成功。')
                    break
                elif choice == 'n':
                    print('取消删除。')
                    break
                else:
                    print('非法输入。')
        break


def admin_check():
    for k, v in user_info.items():
        print('username:%s \t password:%s' % (k, v))


def user_menu():
    while True:
        print('帐号管理系统'.center(50, '`'))
        print("""
    
                    1.登陆
                    2.注册
                    3.返回上层目录
                    4.退出
    
        """)
        print('`' * 55)
        choice = input('请输入服务序号:')
        if choice == '1':
            user_login()
        elif choice == '2':
            user_add()
        elif choice == '3':
            break
        elif choice == '4':
            exit(0)
        else:
            print('非法输入。')


def user_login():
    for i in range(3):
        username = input('username:')
        passwd = input('password:')
        if username not in user_info:
            print('用户名不存在。')
        else:
            if user_info[username] == passwd:
                print('登陆成功。')
                user_menu()
                break
            else:
                print('密码错误。')
    else:
        print('登陆错误超过三次请稍后再试。')


def user_add():
    while True:
        name_add = input('username:')
        if name_add in user_info:
            print('用户名已存在。')
            continue
        else:
            while True:
                passwd_add = input('password:')
                passwd_add0 = input('repeat:')
                if passwd_add != passwd_add0:
                    print('两次输入密码不一致。')
                    continue
                else:
                    user_info[name_add] = passwd_add
                    print('会员注册成功。')
                    break
        break


def main():
    while True:
        menu()
        choice = input('请输入服务序号:')
        if choice == '1':
            admin_login()
        elif choice == '2':
            user_menu()
        elif choice == '3':
            exit(0)
        else:
            print('非法输入。')


main()

猜你喜欢

转载自blog.csdn.net/Sangyumo/article/details/81708007