图书管理系统-python

简介: 图书管理系统-python

图书管理系统-python语言

简介:

这个题的原题是需要C++来写的,然后C++的完整代码我放在了这个博客:图书目录管理系统(C++),然后我用python在模拟一个过程的,没有完全按照题目来做,比较简单,后面补加一个链接了数据库的版本。

题目原型:

请设计一个简单的图书目录管理系统(初级版)。

图书目录信息包括:

统一书号(不超过13字符)

书名(不超过30字符)

作者(不超过20字符)

出版社(不超过30字符)

出版日期(包括:年、月、日)

价格(精确到分)

注意:为了保证运行窗口能正确地显示,请右击运行窗口,修改“属性”:

在“选项”选项卡中,选中“使用旧版本控制台”

在“字体”选项卡中,选择“8×16”“点阵字体”

在“布局”选项卡中,将屏幕窗口宽度均设为“120”。

具体需求如下:

显示如下的主菜单:

Append Find Remove Modify Show Quit > _

如果用户输入 A 或 a、F 或 f、R 或 r、M 或 m、S 或 s,则可完成相应的操作。如果用户输入其它字符,则显示错误信息。

程序将反复显示主菜单,让用户持续工作。如果用户输入 Q 或 q,则程序结束。

Append Find Remove Modify Show Quit > Q
Thank you! Goodbye!

若用户输入其它字符,则显示错误信息。

Append Find Remove Modify Show Quit > B
Incorrect choice!
Append Find Remove Modify Show Quit > 9
Incorrect choice!
Append Find Remove Modify Show Quit > +
Incorrect choice!

若用户输入 A 或 a,则可以输入新书的信息,将其添加到图书目录中。

Append Find Remove Modify Show Quit > a
     ISBN: 9780439227148
    Title: The Call of the Wild
   Author: Jack London
Publisher: Scholastic Press
 Pub date: 2001/1/1
    Price: 39.4
Append Find Remove Modify Show Quit > A
     ISBN: 9781772262902
    Title: Oliver Twist
   Author: Charles Dickens
Publisher: Engage Books
 Pub date: 2016/9/15
    Price: 648
Append Find Remove Modify Show Quit > a
     ISBN: 9787515911076
    Title: The Call of the Wild
   Author: Jack London
Publisher: Aerospace Publishing House
 Pub date: 2016/5/1
    Price: 29.8

若用户输入的日期信息不正确,则显示错误信息,并要求用户重新输入。

Append Find Remove Modify Show Quit > A
     ISBN: 9787501592401
    Title: The Old Man and the Sea
   Author: Ernest Hemingway
Publisher: Knowledge Press
 Pub date: 2016/2/30
Incorrect date! Please reenter: 2016/6/31
Incorrect date! Please reenter: 2016/8/1
    Price: 25.8

若用户输入 S 或 s,则按书号升序排序,然后列表显示全部图书。

Append Find Remove Modify Show Quit > S
ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9780439227148 The Call of the Wild           Jack London          Scholastic Press               2001/01/01    39.40
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80

若用户输入 F 或 f,则输入书名,然后显示该书名的图书。如果没有对应的图书,则显示错误信息。

Append Find Remove Modify Show Quit > F
Title: The Call of the Wild
ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9780439227148 The Call of the Wild           Jack London          Scholastic Press               2001/01/01    39.40
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80
Append Find Remove Modify Show Quit > f
Title: Gulliver's Travels
Not found!

说明:输出查找结果时,不作排序操作。

若用户输入 R 或 r,则输入书号,然后将删除该书号的图书。如果没有对应的图书,则显示错误信息。

Append Find Remove Modify Show Quit > r
ISBN: 9781772262902
Remove(y/n)? n
Append Find Remove Modify Show Quit > S
ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9780439227148 The Call of the Wild           Jack London          Scholastic Press               2001/01/01    39.40
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80
Append Find Remove Modify Show Quit > R
ISBN: 9780439227148
Remove(y/n)? Y
Append Find Remove Modify Show Quit > s
ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80
Append Find Remove Modify Show Quit > r
ISBN: 9787515914145
Not found!
Append Find Remove Modify Show Quit > s
ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80

要求:用户回答是否删除时,必须回答 Y 或 N (大小写均可)。如果是其它字符,则显示错误信息,要求用户重新回答。

Append Find Remove Modify Show Quit > R
ISBN: 9781772262902
Remove(y/n)? k
Incorrect answer!
Remove(y/n)? $
Incorrect answer!
Remove(y/n)? N

若用户输入 M 或 m,则可以修改图书信息。首先按书号查找,然后重新输入该图书的信息。

Append Find Remove Modify Show Quit > m
ISBN: 9787515911076
Modify(y/n)? y
     ISBN: 9787544724968
    Title: The House on Mango Street
   Author: Sandra Heathneros
Publisher: Yilin Press
 Pub date: 2012/1/1
    Price: 30
Append Find Remove Modify Show Quit > M
ISBN: 9787501592401
Modify(y/n)? n
Append Find Remove Modify Show Quit > m
ISBN: 9787515914145
Not found!
Append Find Remove Modify Show Quit > S
ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787544724968 The House on Mango Street      Sandra Heathneros    Yilin Press                    2012/01/01    30.00

要求:用户回答是否修改时,必须回答 Y 或 N (大小写均可)。如果是其它字符,则显示错误信息,要求用户重新回答。

Append Find Remove Modify Show Quit > M
ISBN: 9787544724968
Modify(y/n)? K
Incorrect answer!
Modify(y/n)? *
Incorrect answer!
Modify(y/n)? n

相关习题:图书目录管理系统(高级版)。

Append Find Remove Modify Show Quit > Thank you! Goodbye!
q

完整代码

class Book:
    def __init__(self, ISBN, title, author, publisher, pubdate, price):
        self.ISBN = ISBN
        self.title = title
        self.author = author
        self.publisher = publisher
        self.pubdate = pubdate
        self.price = price
    def Print(self):
        # 打印book的各个属性
        print(self.ISBN + " " + self.title + " " + self.author + " " + self.publisher + " " + self.price)
class BookLibrary:
    def __init__(self):
        self.library = []
    def add(self):
        print("请输入你需要添加的书的信息:")
        # 创建Book对象
        book = Book(None, None, None, None, None, None)
        book.ISBN = input("ISBN:")
        book.title = input("Title:")
        book.author = input("Author:")
        book.publisher = input("Publisher:")
        book.pubdate = input("Pubdate:")
        book.price = input("Price:")
        self.library.append(book)
    # 更新书本
    def update(self):
        ISBN = input("请输入你需要更新的书本的ISBN:")
        book = self.findByISBN(ISBN)
        if book == None:
            print("没有找到这本书")
            return
        print("输入新的书本的信息:")
        book.ISBN = input("ISBN:")
        book.title = input("Title:")
        book.author = input("Author:")
        book.publisher = input("Publisher:")
        book.pubdate = input("Pubdate:")
        book.price = input("Price:")
    def delete(self):
        ISBN = input("请输入你需要删除的书本的ISBN:")
        book = self.findByISBN(ISBN)
        if book == None:
            print("没有找到这本书")
            return
        self.library.remove(book)
    def selectAll(self):
        print("ISBN----------Title----------Author----------Publisher----------Price")
        for book in self.library:
            book.Print()
    # 按照ISBN查询
    def findByISBN(self, ISBN):
        for book in self.library:
            if book.ISBN == ISBN:
                return book
        else: # 这是没有查询到的情况
            return None
if __name__=="__main__":
    # 创建一个图书馆
    booklirary = BookLibrary()
    # 测试添加
    booklirary.add()
    # 测试查询
    booklirary.selectAll()
    # 测试更新
    booklirary.update()
    booklirary.selectAll()
    # 测试删除
    booklirary.delete()
    booklirary.selectAll()


相关文章
|
2月前
|
存储 前端开发 数据库
基于python flask 的图书管理系统,有登录界面,实现简单增删改查,可以做课程设计使用
本文介绍了一个基于Python Flask框架的图书管理系统,该系统具备登录界面,并实现了基本的增删改查功能,适合作为课程设计使用。
基于python flask 的图书管理系统,有登录界面,实现简单增删改查,可以做课程设计使用
|
2月前
|
前端开发 关系型数据库 MySQL
Python基于Django框架图书管理系统,Bootstrap框架UI,后台EasyUI框架UI,有登录,实现增删改查的富文本效果
本文介绍了一个使用Python Django框架开发的图书管理系统,该系统采用Bootstrap框架进行前端UI设计,EasyUI框架用于后台UI界面,集成了富文本编辑器,并实现了登录及增删改查功能。
|
2月前
|
存储 数据可视化 数据安全/隐私保护
【python】python图书管理系统_普通用户+管理员菜单(源码+论文)【独一无二】
【python】python图书管理系统_普通用户+管理员菜单(源码+论文)【独一无二】
|
存储 小程序 数据库管理
【python基础知识】14.图书管理系统的搭建(类与对象实操)
【python基础知识】14.图书管理系统的搭建(类与对象实操)
323 0
|
10月前
|
存储 Java C++
用python写图书管理系统
用python写图书管理系统
198 4
|
存储 Python
python实现图书管理系统(超详细)
python实现图书管理系统 图书管理系统 python实现图书管理系统 图书管理系统: 图书的功能: 现在开始添加数据: 增加数据 删除数据 查询数据 图书位置修改 图书的借出 图书的还回 主体界面 完整代码 功能运行截图
1498 0
python实现图书管理系统(超详细)
|
Python
Python分分钟实现图书管理系统(含代码)
Python分分钟实现图书管理系统(含代码)
355 0
|
存储 前端开发 关系型数据库
Python图书管理系统(终章)
Python图书管理系统(终章)
395 0
Python图书管理系统(终章)
|
SQL 存储 前端开发
Python图书管理系统(二)
Python图书管理系统(二)
357 0
Python图书管理系统(二)
|
存储 关系型数据库 MySQL
Python图书管理系统(一)
初识python的小乐趣
408 0
Python图书管理系统(一)