Question: Part 1 : Create a Class ( ~ 6 points ) Create a class called Book with the following instance variables: title ( string )

Part 1: Create a Class(~6 points)
Create a class called Book with the following instance variables:
title (string)author (string)price (float)
Add a constructor to initialize these variables.Write a method display_details that prints all the details of the book in a neat format.
Part 2: Access Control(~6 points)
Add a private variable __discount (float) in the Book class with a default value of 0.1.Write a public method get_discount that returns the value of __discount.Write another method set_discount to update the discount value (with input validation ensuring it is between 0 and 0.5).
Part 3: Object Instantiation(~6 points)
Create three objects of the Book class using different values.Call display_details for each object.Access and modify the discount using the getter and setter methods.
(Optional Bonus)Part 4: Add Another Class
Create a class Library to manage a collection of books.Add a method add_book that takes a Book object and stores it in a list.Add a method list_books to display all books in the library.
Deliverables:
A Python script file containing the Book and Library classes and the code to test them.

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 Programming Questions!