The purpose of this assignment is to reinforce Python concep
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
Solution
class Book:
author = \"\"
title = \"\"
numOfPages = 0
def __init__(self, author, title, numOfPages):
self.author = author
self.title = title
self.numOfPages = numOfPages
book1 = Book(\"Suresh\",\"Computer Science\", 500);
print(\"Author: \"+book1.author)
print(\"Title: \"+book1.title)
print(\"Number of Pages: \"+str(book1.numOfPages))
Output:
sh-4.3$ python3 main.py
Author: Suresh
Title: Computer Science
Number of Pages: 500
