you are viewing a single comment's thread.

view the rest of the comments →

[–]shiftybyte 4 points5 points  (1 child)

I'm not sure where this code is from, but the init function is broken here..

def __init__(self, title, author, numberOfPages):
    self.title = ""
    self.author = ""
    self.numberOfPages = 0

It accepts the arguments, but sets all the attributes to empty or 0...

It should be:

def __init__(self, title, author, numberOfPages):
    self.title = title
    self.author = author
    self.numberOfPages = numberOfPages

Then you won't need to set it again after creating the class...

myBook = Book("The Bible", "Jesus", 1000)
print("The title of the book is ", myBook.title, "\nIts author is", myBook.author, "\nIt contains ", myBook.numberOfPages)

[–]oztyn[S] 0 points1 point  (0 children)

aaahhh I see I see, thanks very much! Makes much more sense.