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

TP3 Python 24 - 25

Uploaded by

bedairiainel
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)
18 views2 pages

TP3 Python 24 - 25

Uploaded by

bedairiainel
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

Electronic Department

ING RSI Lab Work 3


Classes, objects, methods and modules

I. OBJECTIVES OF THE LAB WORK:


1. Mastering the oop concepts in python
2. Working with classes and objects
3. Implementing constructor
4. Implementing methods
5. Understand the purpose and usage of modules in Python.

II. TASKS:
PART I: Using classes, objects and methods

1. Create a Python class named BankAccount.


2. Add the following attributes to the class:

 account_holder (a string representing the name of the account holder)


 balance (a float representing the current balance of the account)

3. Implement the __init__ method to initialize the account_holder and balance


attributes when an object is created.
4. Implement methods for the following actions:

 deposit: Accepts an amount and adds it to the balance.


 withdraw: Accepts an amount and subtracts it from the balance if there are
sufficient funds.
 get_balance: Returns the current balance of the account.
 display_account_info: Displays the account holder's name and current
balance.

5. Create an instance of the BankAccount class and test the methods by depositing and
withdrawing funds, checking the balance, and displaying the account information.

PART II: Using Modules and Classes

 Setup: Create a Module for the System


 Create a Python module named library.py that includes all classes for the system.
 Define Classes in the Module Inside library.py, define the following classes:

 Book

 Attributes: book_id, title, author, availability (boolean)


 Methods:

 __init__(self, book_id, title, author): Initialize book details.


 mark_as_borrowed(self): Change availability to False.
 mark_as_returned(self): Change availability to True.
 Member

 Attributes: member_id, name, borrowed_books (list of books)


 Methods:

 __init__(self, member_id, name): Initialize member details.


 borrow_book(self, book): Add a book to the borrowed list if available.
 return_book(self, book): Remove a book from the borrowed list.
 Library

 Attributes: books (list of Book), members (list of Member)


 Methods:

 add_book(self, book): Add a book to the library.


 add_member(self, member): Add a member to the library.
 find_book(self, book_id): Search for a book by ID.
 list_available_books(self): Display all books that are available.

 Main Program

 Create a separate file, main.py, to act as the main program.


 Import the library.py module.
 Add a menu-based system for the user:
1. Add a new book.
2. Add a new member.
3. Borrow a book.
4. Return a book.
5. List all available books.
6. Exit.

 Test your program

Test thoroughly your program by creating different objects and testing the methods in
order to ensure proper functionality of the system.

You might also like