Object Oriented Python: Extending Class, you didn't finish how to print from book and textbook. You left off how to print the output from class book and textbook. You left out print(b.str()). You show how to add in def str(self): but you didn't show how to call it.
#!/usr/bin/env/python3
class Book:
def __init__(self, title, author):
self.title = title
self.author = author
def __str__(self):
return 'Book: {} by {}'.format(self.title, self.author)
class Textbook(Book):
def __init__(self, title, author, edition) -> object:
super().__init__(title, author)
self.edition = edition
def __str__(self):
return 'Textbook: {} by {} edition {}'.format(self.title, self.author, self.edition)
#!/usr/bin/env/python3
def main():
from classes import Book
from classes import Textbook
b = Book('The Hitchhikers Guide to the Galaxy', 'Douglas Adams')
print(b.__str__())
b = Textbook('Cisco CCNP', 'Todd Lammle', '5')
print(b.__str__())
if __name__ == '__main__':
main()
Output
Book: The Hitchhikers Guide to the Galaxy by Douglas Adams
Textbook: Cisco CCNP by Todd Lammle edition 5