diff --git a/Finished/Ch 4/challenge.py b/Finished/Ch 4/challenge.py index 0cb2b0b..e48751a 100644 --- a/Finished/Ch 4/challenge.py +++ b/Finished/Ch 4/challenge.py @@ -33,10 +33,10 @@ def __lt__(self, other): # ~~~~~~~~~ TEST CODE ~~~~~~~~~ stocks = [ - Stock("MSFT", 342.0, "Microsoft Corp"), - Stock("GOOG", 135.0, "Google Inc"), - Stock("META", 275.0, "Meta Platforms Inc"), - Stock("AMZN", 120.0, "Amazon Inc") + Stock(342.0, "MSFT", "Microsoft Corp"), + Stock(135.0, "GOOG", "Google Inc"), + Stock(275.0, "META", "Meta Platforms Inc"), + Stock(120.0, "AMZN", "Amazon Inc") ] bonds = [ diff --git a/Start/Ch 2/abstract_start.py b/Start/Ch 2/abstract_start.py index dece2ad..9dfd151 100644 --- a/Start/Ch 2/abstract_start.py +++ b/Start/Ch 2/abstract_start.py @@ -1,15 +1,17 @@ # Python Object Oriented Programming by Joe Marini course example # Using Abstract Base Classes to enforce class constraints +#TODO: Import "ABC"(abstract base classes) and abstractmethod from abc +#TODO: Inherit from ABC indicates that this is an abstract base class class GraphicShape: def __init__(self): super().__init__() - + # declaring a method as abstract requires a subclass to implement it def calcArea(self): pass - +#TODO: Create specific versions of "calcArea" for different shapes class Circle(GraphicShape): def __init__(self, radius): self.radius = radius diff --git a/Start/Ch 2/composition_start.py b/Start/Ch 2/composition_start.py index ccf9423..614c22c 100644 --- a/Start/Ch 2/composition_start.py +++ b/Start/Ch 2/composition_start.py @@ -1,7 +1,7 @@ # Python Object Oriented Programming by Joe Marini course example # Using composition to build complex objects - +#TODO: Arrange the composition of the Book class to operate on subclasses class Book: def __init__(self, title, price, authorfname, authorlname): self.title = title @@ -15,6 +15,13 @@ def __init__(self, title, price, authorfname, authorlname): def addchapter(self, name, pages): self.chapters.append((name, pages)) + #TODO: Method for counting the total number of pages from all chapters + +#TODO: Create classes "Chapter"(with attributes "name" and "pages") +# and "Author" with ("fname" and "lname") and a method __str__ returning author details + + +#TODO: Create an author object and add it to the book b1 = Book("War and Peace", 39.0, "Leo", "Tolstoy") diff --git a/Start/Ch 2/inheritance_start.py b/Start/Ch 2/inheritance_start.py index 7ac7685..31485b2 100644 --- a/Start/Ch 2/inheritance_start.py +++ b/Start/Ch 2/inheritance_start.py @@ -1,7 +1,12 @@ # Python Object Oriented Programming by Joe Marini course example # Understanding class inheritance +#TODO: Create a class "Publication" with attributes "title" and "price" +#TODO: Create a class "Perdiodicaly" that inherits from "Publication" +# and additionally has attributes "period" and "publisher" + +#TODO: Allow the "Book" class to inherit attributes from Publication class Book: def __init__(self, title, author, pages, price): self.title = title @@ -9,7 +14,7 @@ def __init__(self, title, author, pages, price): self.author = author self.pages = pages - +#TODO: The Magazine and Newspaper classes can inherit all atributes from "Perdiodicaly" class Magazine: def __init__(self, title, publisher, price, period): self.title = title diff --git a/Start/Ch 2/interface_start.py b/Start/Ch 2/interface_start.py index adb6334..7027779 100644 --- a/Start/Ch 2/interface_start.py +++ b/Start/Ch 2/interface_start.py @@ -12,6 +12,7 @@ def __init__(self): def calcArea(self): pass +# TODO: Add abstract class "JSONify" with abstract method "toJSON" class Circle(GraphicShape): def __init__(self, radius): @@ -19,6 +20,8 @@ def __init__(self, radius): def calcArea(self): return 3.14 * (self.radius ** 2) + + # TODO: Override "toJSON" method to return a JSON representation of "calcArea" c = Circle(10) diff --git a/Start/Ch 2/multiple_start.py b/Start/Ch 2/multiple_start.py index 5e76252..dc5b9b6 100644 --- a/Start/Ch 2/multiple_start.py +++ b/Start/Ch 2/multiple_start.py @@ -1,7 +1,7 @@ # Python Object Oriented Programming by Joe Marini course example # Understanding multiple inheritance - +#TODO: For A and B class create an attribute "name" that will take different values class A: def __init__(self): super().__init__() @@ -17,6 +17,7 @@ def __init__(self): class C(A, B): def __init__(self): super().__init__() - + #TODO: Create the method "showprops" returning the attributes it owns c = C() +#TODO: You can use showprops() and also call "Class.__mro__" to find out all the parent classes diff --git a/Start/Ch 4/dataclass_start.py b/Start/Ch 4/dataclass_start.py index 77ee283..fa31476 100644 --- a/Start/Ch 4/dataclass_start.py +++ b/Start/Ch 4/dataclass_start.py @@ -1,6 +1,7 @@ # Python Object Oriented Programming by Joe Marini course example # Using data classes to represent data objects +#TODO: Import dataclasses from dataclass and apply decorator class Book: def __init__(self, title, author, pages, price): diff --git a/Start/Ch 4/datadefault_start.py b/Start/Ch 4/datadefault_start.py index 43998a1..c48cf60 100644 --- a/Start/Ch 4/datadefault_start.py +++ b/Start/Ch 4/datadefault_start.py @@ -1,8 +1,12 @@ # Python Object Oriented Programming by Joe Marini course example # implementing default values in data classes +# TODO: Import "field" function from dataclasses from dataclasses import dataclass +# TODO: Define a function that returns a random number between 20-40. +# Don't forget to import the necessary module + @dataclass class Book: @@ -11,3 +15,4 @@ class Book: author: str pages: int price: float + # TODO: Use the field function to get default price as random number diff --git a/Start/Ch 4/immutable_start.py b/Start/Ch 4/immutable_start.py index d214eab..41c8710 100644 --- a/Start/Ch 4/immutable_start.py +++ b/Start/Ch 4/immutable_start.py @@ -10,7 +10,7 @@ class ImmutableClass: value2: int = 0 -obj = ImmutableClass() +obj = ImmutableClass() # You can set the values of frozen class only with initialization print(obj.value1) # TODO: attempting to change the value of an immutable class throws an exception