Question: Problem 1: Objects Please code this in Python Create a class Book with title and number_of_pages attributes. Define __init__, __str__ and __add__ methods. __add__ method

Problem 1: Objects

Please code this in Python

Create a class Book with title and number_of_pages attributes.

Define __init__, __str__ and __add__ methods.

__add__ method will take another Book object as an argument and return the sum of pages in the two books.

To demonstrate you will create two instances of Book object and output the sum of pages in the two books.

Example output is:

book1_inst = Book(Think Python, 300)

book2_inst = Book(Monty Python, 100)

Sum of pages in book-Think Python and book-Monty Python is 400.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!