0% found this document useful (0 votes)
7 views2 pages

Lab Performance-F01

SP3

Uploaded by

2kawserahmed7
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)
7 views2 pages

Lab Performance-F01

SP3

Uploaded by

2kawserahmed7
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/ 2

Problem Statement:

You are to create a simple library management system that models basic library operations
using classes and encapsulation while utilizing dictionaries for storing library items.

Requirements:

1. Class Design:
○ Create a class named Library.
○ The class should have the following attributes:
■ library_name (string)
■ items (dictionary) to store library items, where the key is the item ID
(string) and the value is another dictionary containing:
■ title (string)
■ author (string)
■ is_checked_out (boolean, default: False)
2. Constructor:
○ The constructor (__init__ method) should initialize library_name and an
empty dictionary for items.
3. Methods:
○ Add Item: Create a method named add_item(item_id, title, author)
that:
■ Adds a new item to the items dictionary with the given item ID, title, and
author.
○ Check Out: Create a method named check_out(item_id) that:
■ Checks if the item exists and is not already checked out.
■ Sets is_checked_out to True if the item is available.
■ Returns a success message or an error message if the item is already
checked out.
○ Return Item: Create a method named return_item(item_id) that:
■ Checks if the item exists and is currently checked out.
■ Sets is_checked_out to False if the item is checked out.
■ Returns a success message or an error message if the item is not
checked out.
○ Get Item Info: Create a method named get_item_info(item_id) that:
■ Returns the information of the item (title, author, and check-out status) or
an error message if the item does not exist.
4. Encapsulation:
○ Ensure that direct access to the items dictionary is not possible from outside the
class by using private attributes.
5. Testing:
○ Create an instance of the Library class in the main section of your code.
○ Demonstrate the functionality by performing the following operations:
■ Add several items to the library.
■ Check out an item.
■ Attempt to check out the same item again.
■ Return the item and check its information.
■ Print the information for all items in the library.

Example Output:

Library: City Library

Adding items to the library...


Adding "The Great Gatsby" by F. Scott Fitzgerald with ID "001".
Adding "1984" by George Orwell with ID "002".

Checking out item "001"...


Successfully checked out "The Great Gatsby".

Checking out item "001" again...


Error: "The Great Gatsby" is already checked out.

Returning item "001"...


Successfully returned "The Great Gatsby".

Information for all items:


Item ID: 001
Title: The Great Gatsby
Author: F. Scott Fitzgerald
Checked Out: False

Item ID: 002


Title: 1984
Author: George Orwell
Checked Out: False

You might also like