[Solved] What is wrong with my “summarize” command?


Python is not Java. You don’t need setter functions for every property.

Use the __init__ method to initialize your object:

class Textbook:
    def __init__(self, title, author, publisher, year,
                 course, semester):
        self.title = title
        self.author = author
        self.publisher = publisher
        self.year = year
        self.course = course
        self.semester = semester

    def summarize(self):
        s="{:40s} {:15s} {:15s} {:4d} {:8s} {:7s}"
        return s.format(self.title, self.author,
                        self.publisher, self.year,
                        self.course, self.semester)


my_textbooks=[]

mybook1 = Textbook("Introduction to Python Class", "Inseok Song",
                   "UGA", 2016, "PHYS2001", "2016fa")
my_textbooks.append(mybook1)
# You can also create a textbook and add it to the list at
# the same time.
my_textbooks.append(Textbook("Calculus III", "LaFollette",
                   "Blackwell", 2006, "MATH2270", "2017fa"))
for book in my_textbooks:
    # Print whatever you like as a summary
    print(book.summarize())

3

solved What is wrong with my “summarize” command?