Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started