The purpose of this assignment is to reinforce Python concepts. Define a class in Python and use it to create an object and display its components. Define a Book class where a book contains the following components:
an author
a title
a number of pages
The “main program” needs to create a book and then display its contents
# Book program in Python
class Book:
def __init__(self, author, title, noOfPages):
self.author = author
self.title = title
self.noOfPages = noOfPages
def displayBook(self):
print "Author : ", self.author, ", Title: ", self.title, ", Number
of Pages: %d" % self.noOfPages
book = Book("J.K.Rowling", "Harry Potter", 672)
book.displayBook()
=======Sample Output========
Author : J.K.Rowling , Title: Harry Potter , Number of Pages: 672
Get Answers For Free
Most questions answered within 1 hours.