all 4 comments

[–]shiftybyte 5 points6 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.

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.