Q21Comprehension4 Marks3 Sep 2023
Passage
Based on the above data, answer the given subquestions. Consider the class Product:
```
class Product:
def __init__(self, title, price):
self.title = title
self.price = price
def change_price(self, price):
self.price = price
def print_info(self):
print(f'Product title: {self.title}')
print(f'Product price: {self.price}')
Book is a sub-class of Product:
class Book(Product):
count = 0
def __init__(self, title, price, author, genre):
super().__init__(title, price)
self.author = author
self.genre = genre
Book.count += 1
def is_fiction(self):
return self.genre == "Fiction"
def print_info(self):
super().print_info()
print('Product is a book')
print(f'Author: {self.author}')
print(f'Genre: {self.genre}')
```
Assume that library represents a list of objects of type Book. What does the variable count represent at the end of execution of this code?
```
# assume that library has n elements, only three of which are shown below
# Book.count = 0
library = [Book('A brief history of time', 250, 'Hawking', 'Non Fiction'),
Book('Alice in wonderland', 100, 'Carroll', 'Fiction'),
Book('Feynman lectures in Physics', 400, 'Feynman', 'Non Fiction')]
count = 0
for book in library:
if book.is_fiction():
count = count + 1
```