- This event has passed.
2 PM – Python Object Oriented Programming – Sebastian
July 29, 2023 @ 2:00 pm - 3:00 pm
Today We Did
- Completed School System
- Began Library System
- Continued to understand the differences between attributes and variables
- In case you need anything, feel free to email me at sebastian@ayclogic.com
Homework
- Create a new folder on your homework submissions called “Library System”
- Homework: Complete the remaining methods we mentioned in class. I want you to try your best to reflect on our previous SchoolSystem to think about what we should put in these new methods. Remember user input, the dictionary attributes, and how we loop through dictionaries.
class code & instructions we went over:
from book import Bookclass LibrarySystem:def __init__(self):self.menu = “””Please look at below options1. Add book2. List all books3. Find book by name4. Find book by id5. List all old booksEnter your selection. Enter ‘quit’ to exit: “””self.title_to_book = {}self.id_to_book = {}def add_book(self):print(“\nADD NEW BOOK”)title = input(“What is the title? “)author = input(“Who is the author? “)publish_year = input(“When was it published? “)book_id = input(“Enter book id: “)book = Book(title, author, publish_year, book_id)self.title_to_book[title] = bookself.id_to_book[book_id] = book“””for all methods which print book info; choose whether to print each attribute or make a method inside the book class“””“””list_all_books_using_dictionary“””def list_all_books_using_dictionary(self):print(“\nLIST ALL BOOKS”)# loop through each book object using ANY of our dictionariesfor book in self.title_to_book.values():pass“””list_all_old_booksonly print books whose publish_year is less than 2000(when should you turn the publish year to an integer?)“””“””find_book_using_id(use id_to_book dictionary attribute)“””“””find_book_using_title(use title_to_book dictionary attribute)“””def application_loop(self):while True:selection = input(self.menu)if selection == “quit”:print(“Thank you for using the Libray System.”)breakif selection == “1”:self.add_book()s = LibrarySystem()s.application_loop()