Python图书馆管理系统

import datetime
from urllib import parse
import hashlib

__author__ = 'rxz'

account = {'admin': 123456, 'guest': 123456}
registerTime = {}
book = ["水浒传", "西游记", "时间简史", "圆圈正义"]


def menu():
    print()
    print("==============图书管理系统==============")
    print("欢迎讨论指正! qq1052335231")
    print("请登录:1.普通用户  2.注册  3.管理员登录 0.退出 5.密码加密")
    i = int(input())
    if i == 1:
        login()
        menu()
    elif i == 2:
        register()
        menu()
    elif i == 3:
        logi()
        wen()
    elif i == 5:
        jia()


def jia():
    hash = hashlib.md5()  # 创建了一个md5算法的对象(md5不能反解),即造出hash工厂
    hash.update(bytes('123456', encoding='utf-8'))  # 运送原材料喽,要对哪个字符串进行加密,就放这里
    print("加密后密码为:", hash.hexdigest())  # 产出hash值,拿到加密字符串


def logi():
    print("请输入用户名:")
    usm = input()
    print("请输入密码:")
    pwd = input()
    if usm in account and int(pwd) == account[usm] and usm == 'admin':
        wen()
    elif usm in account and int(pwd) == account[usm]:
        guest(usm)


def login():
    print("请输入用户名:")
    usm = input()
    print("请输入密码:")
    pwd = input()
    if usm in account and int(pwd) == account[usm] and usm == 'admin':
        admin(usm)
    elif usm in account and int(pwd) == account[usm]:
        guest(usm)


def register():
    print("请输入用户名:")
    usm = input()
    print("请输入密码:")
    pwd = input()
    if usm not in account:
        account[usm] = int(pwd)
        print("注册成功!")
        registerTime[usm] = datetime.datetime.now()
    else:
        print("该用户名已被注册!")
        register()


def admin(usm):
    print("登陆成功!")
    print("请输入你的操作:1.管理用户  2.修改密码  3.查看个人信息  4.进入图书系统 0.退出")
    choice = int(input())
    if choice == 1:
        manager()
        admin(usm)
    elif choice == 2:
        fixPwd(usm)
        admin(usm)
    elif choice == 3:
        show(usm)
        admin(usm)
    elif choice == 4:
        put()


def put():
    print("请输入你的操作:1.查询书籍  2.借阅书籍 3.归还书籍 0.退出")
    choice = int(input())
    if choice == 1:
        print(book)
        put()
    elif choice == 2:
        iu = input("请输入借阅书籍的名字:")
        if iu not in book:
            print("图书系统无此书")
            put()
        else:
            print("借阅成功")
            put()
    elif choice == 3:
        iu = input("请输入归还书籍的名字:")
        print("归还成功")
        print("归还书后可领取一只宠物")
        pet()
    elif choice == 0:
        exit()


def manager():
    print("用户列表\n", account)
    print("1.修改  2.删除  0.退出")
    choice = int(input())
    if choice == 1:
        pass
    elif choice == 2:
        pass


def guest(usm):
    print("1.修改密码  2.查看个人信息  0.退出")
    choice = int(input())
    if choice == 1:
        fixPwd(usm)
        guest(usm)
    elif choice == 2:
        show(usm)
        guest(usm)


def fixPwd(usm):
    print("请输入新密码:")
    pwd = int(input())
    print("请再次输入新密码")
    pwd1 = int(input())
    if pwd == pwd1:
        account[usm] = pwd
        print("修改成功!")
    else:
        print("修改失败,两次密码不一致!")


def show(usm):
    print(f"用户名:{usm},密码{account[usm]},注册时间{registerTime[usm]}")


def wen():
    print("请输入你的操作:1.添加书籍 2.删除书籍 3.改书籍价格 4.查看书籍")
    iu = int(input())
    if iu == 1:
        a = input("请输入你要添加的书籍名:")
        book.add(a)
        print("现有书籍:", book)
    elif iu == 2:
        a = int(input("请输入你要删除的书籍?  1.水浒传 2.西游戏 3.圆圈正义\n"))
        if a == 1:
            book.remove("水浒传")
            print("现有书籍:", book)
        elif a == 2:
            book.remove("西游记")
            print("现有书籍:", book)
        elif a == 3:
            book.remove("圆圈正义")
            print("现有书籍:", book)
    elif iu == 4:
        print("现有书籍:", book)


def jin():
    a = 5
    b = 3
    c = 4
    print(f"现在有水浒传{a}本,西游记{b}本,圆圈正义{c}本")


def pet():
    print("是否查看宠物:1.是 2.否")
    iu = int(input())
    if iu == 1:
        print("冰龙王,喵喵,火焰猴,齐天大圣")
    a = ["冰龙王", "喵喵", "火焰猴", "齐天大圣"]
    print("请选择你要领取的宠物:1.冰龙王 2.喵喵 3.火焰猴 4.火焰猴")
    i = int(input())
    if i == 1:
        print("冰龙王领取成功")
    elif i == 2:
        print("喵喵领取成功")
    elif i == 3:
        print("火焰猴领取成功")
    elif i == 4:
        print("火焰猴领取成功")


if __name__ == '__main__':
    registerTime['admin'] = datetime.datetime.now()
    registerTime['guest'] = datetime.datetime.now()
    menu()

 

你可能感兴趣的:(Python,python)