This program will simulate a small "database" of information about books in a library, bookstore, etc. The information for each book will be stored in a dictionary, and all the dictionaries will be stored in a list. With this program, you will be able to:
- See a list of books
- Add a new book to the database
- Fetch more detailed information about a book
+ Expand Code
# An empty list, when the program first
# starts. As the user starts to add
# books, it will be filled with items --
# those items being dictionaries containing
# book information
books = []
choice = None
while choice != "0":
print(
"""
Create Books
...
- Collapse Code
# An empty list, when the program first
# starts. As the user starts to add
# books, it will be filled with items --
# those items being dictionaries containing
# book information
books = []
choice = None
while choice != "0":
print(
"""
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
"""
)
choice = input("Choice: ")
print()
# exit
if choice == "0":
print("Good-bye.")
# display books
elif choice == "1":
print("Books:\n")
# This part of the program should print
# each book's number (its index in the
# list) and its title
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
# add a book
elif choice == "2":
# This part of the program should:
# -Create an empty dictionary
# -Add keys to the dictionary for
# title
# author
# year
# pages
# while getting the values through
# user input. (Here, "year" means
# the year of publication.)
# -Append the newly-filled dictionary
# to the list books
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
# delete a book
elif choice == "3":
# This part of the program should:
# -List the numbers and titles
# for the books currently in
# the system. For this part, you
# can reuse the code from choice
# number 1 above.
# -Get the number for the book
# from the user, converted to int
# -Use the number as the INDEX to
# delete the item from the list books
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
# print info about a book
elif choice == "4":
# This part of the program should:
# -List the numbers and titles
# for the books currently in
# the system. For this part, you
# can reuse the code from choice
# number 1 above.
# -Get the number for the book
# from the user, converted to int
# -Use the number as the INDEX to
# get the item from the list books
# -That item will be a dictionary. For
# each key in the dictionary, print:
# *The key
# *Its corresponding value
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
# some unknown choice
else:
print("Sorry, but", choice, "isn't a valid choice.")
print()
- Collapse Code
Note that because of user input and random values, the output will look different each time you run the program.
Program output example:
+ Expand Output
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
Choice: 1
Books:
Create Books
0 - Quit
...
- Collapse Output
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
Choice: 1
Books:
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
Choice: 2
What is the title?: Wuthering Heights
Who is the author?: Emily Bronte
Year of publication?: 1847
How many pages?: 256
Added Wuthering Heights
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
Choice: 2
What is the title?: Jane Eyre
Who is the author?: Charlotte Bronte
Year of publication?: 1847
How many pages?: 624
Added Jane Eyre
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
Choice: 2
What is the title?: Pride and Prejudice
Who is the author?: Jane Austen
Year of publication?: 1813
How many pages?: 272
Added Pride and Prejudice
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
Choice: 1
Books:
0 : Wuthering Heights
1 : Jane Eyre
2 : Pride and Prejudice
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
Choice: 4
Books:
0 : Wuthering Heights
1 : Jane Eyre
2 : Pride and Prejudice
Which number book do you want?: 2
title : Pride and Prejudice
pages : 272
year : 1813
author : Jane Austen
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
Choice: 2
What is the title?: Frankenstein
Who is the author?: Mary Shelley
Year of publication?: 1818
How many pages?: 166
Added Frankenstein
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
Choice: 4
Books:
0 : Wuthering Heights
1 : Jane Eyre
2 : Pride and Prejudice
3 : Frankenstein
Which number book do you want?: 0
title : Wuthering Heights
pages : 256
year : 1847
author : Emily Bronte
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
Choice: 3
Books:
0 : Wuthering Heights
1 : Jane Eyre
2 : Pride and Prejudice
3 : Frankenstein
Which number book do you want?: 2
Deleted Pride and Prejudice
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
Choice: 4
Books:
0 : Wuthering Heights
1 : Jane Eyre
2 : Frankenstein
Which number book do you want?: 1
title : Jane Eyre
pages : 624
year : 1847
author : Charlotte Bronte
Create Books
0 - Quit
1 - List All Books
2 - Add a Book
3 - Delete a Book
4 - Display Book Information
Choice: 0
Good-bye.
- Collapse Output
In at least 150 words, please address the following questions in memo.txt: - How did the process of creating these programs go for you?
- What were your main challenges and how did you overcome them?
- What did you learn that may be of use as you move along in this class?