diff --git a/Start/Ch 1/class_start.py b/Start/Ch 1/class_start.py index 2c824f9..6b7a609 100644 --- a/Start/Ch 1/class_start.py +++ b/Start/Ch 1/class_start.py @@ -4,26 +4,34 @@ class Book: # TODO: Properties defined at the class level are shared by all instances +BOOK_TYPES= ("HARDCOVER", "PAPERBACK", "EBOOK") # TODO: double-underscore properties are hidden from other classes # TODO: create a class method - +@classmethod +def get_book_types(cls): + return cls.BOOK_TYPES # TODO: create a static method # instance methods receive a specific object instance as an argument # and operate on data specific to that object instance def set_title(self, newtitle): self.title = newtitle + if(not booktype in Book.BOOK_TYPES): + raise ValueError(f"{booktype} is not a valid book type") + else: + self.booktype= booktype + - def __init__(self, title): + def __init__(self, title, booktype): self.title = title # TODO: access the class attribute - +print("Book types: ", Book.get_book_types()) # TODO: Create some book instances - - +b1= Book("Title1", "HARDCOVER") +b2= Book("Title1", "COMIC") # TODO: Use the static method to access a singleton object