0% found this document useful (0 votes)
25 views3 pages

Django Scenario

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Django Scenario

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

You are working on a project that involves managing a library of books.

You need
to create a Python program that can handle various operations related to books,
such as adding new books, searching for books by title or author, and calculating
late fees for overdue book returns.

To complete this project, you will need to demonstrate your understanding of the
following concepts:

Python Syntax: Use proper Python syntax to define variables, functions, and
control structures (e.g., loops, conditional statements).

Module Importing and Exporting: Create separate Python modules for different
functionalities, such as book_operations.py and fee_calculator.py. Import and use
the functions defined in these modules within your main program.

Object-Oriented Programming:
Define a Book class with attributes like title, author, publication_year, and
methods like display_info().

Create a Library class that manages a collection of Book objects. It should have
methods to add new books, search for books, and calculate late fees based on
the number of days a book is overdue.

Implement inheritance by creating a ReferenceBook subclass that inherits from


the Book class and has additional attributes or methods specific to reference
books.

User Interaction:
Provide a user interface (console-based or GUI) where users can interact with
your program, such as adding new books, searching for books, and calculating
late fees.

File I/O:
Store and retrieve book information from a file (e.g., CSV, JSON) or a database
(e.g., SQLite).
Step 1: Define the Book class

● Create a new Python file called book.py.


● Define a class called Book with the following attributes: title, author,
publication_year.
● Implement the __init__ method to initialize these attributes when creating a new
Book object.
● Add a method called display_info that prints the book's information.

Step 2: Create the ReferenceBook subclass

● In the same book.py file, create a subclass called ReferenceBook that inherits
from the Book class.
● Add an additional attribute called edition to the ReferenceBook class.
● Override the display_info method to include the edition information when printing
the book's details.

Step 3: Implement the Library class

● Create a new Python file called library.py.


● Define a class called Library with an attribute to store a collection of Book objects
(e.g., a list).
● Implement the following methods in the Library class:
● add_book: Adds a new Book object to the collection.
● search_by_title: Searches for books by their title and returns a list of matching
books.
● search_by_author: Searches for books by their author and returns a list of
matching books.
● calculate_late_fee: Calculates the late fee for a book based on the number of
days it's overdue (you can define your own late fee policy).

Step 4: Create the fee_calculator module

● Create a new Python file called fee_calculator.py.


● Define a function called calculate_late_fee that takes the number of days a book
is overdue and returns the corresponding late fee amount.
Step 5: Import and use the modules

● Create a new Python file called main.py.


● Import the Book and ReferenceBook classes from the book module.
● Import the Library class from the library module.
● Import the calculate_late_fee function from the fee_calculator module.
● Create instances of Book and ReferenceBook objects.
● Create an instance of the Library class and add the book objects to its collection.
● Test the various methods of the Library class, such as search_by_title,
search_by_author, and calculate_late_fee.

Step 6: Implement user interaction

● In the main.py file, create a simple console-based user interface.


● Use input prompts to allow users to perform actions like adding new books,
searching for books, and calculating late fees.
● Call the corresponding methods from the Library class based on the user's input.

Step 7: File I/O

● Create a new Python file called file_operations.py.


● Define functions to read book data from a file (e.g., CSV, JSON) and store it in a
list of Book objects.
● Define functions to write the book data from the Library collection to a file.
● Import and use these functions in the main.py file to persist and load book data.

You might also like