Today we did
Homework
PART 1
PART 2
Part 3 and 4
I want everyone to attempt this
Your general steps is
So here, i wanted to include the code we worked on if you need to catch up . If you are using my template, your goal is the replace the pass, with code and add one line with in add_book
# this is our main file(main.py from book import Book class LibrarySystem: def __init__(self): self.menu = """ Please look at below options 1. Add book 2. List all books 3. Find book by name 4. Find book by id 5. List all old books Enter your selection. Enter 'quit' to exit: """ self.book_dictionary = {} # looks things up with name as key self.books_by_id = {} # looks thing up with id as key def add_book(self): #title,author, publish_year,id title = input("What is the name of the book? : ") author= input("What is the author of the book? :") publish_year= input("what year was it published? :") id= input("what is the id of the book") book_we_want_to_add =Book(title,author,publish_year,id ) #adding the book in the name dictionary self.book_dictionary[title]= book_we_want_to_add #adding the book in the id dictionary def list_all_books(self): pass def search_by_name(self): pass def books_by_id(self): pass
Our book file class Book: def __init__(self,title,author, publish_year,id): self.title=title self.author=author self.publish_year=publish_year self.id=id
Below, I have put some code to test if your code works (you need to add a book to test it). Put it in the bottom of your code to work
system = LibrarySystem() #adds the books system.add_book() # make sure there is two print statements so that you add the dictionary to both print(system.book_dictionary) print(system.books_by_id) # testing parts 2,3,4 system.list_all_books() system.search_by_name() system.search_by_id()