BMS INSTITUTE OF TECHNOLOGY AND
MANAGEMENT
(An Autonomous Institution, Affiliated to VTU, Belagavi)
Avalahalli, Doddaballapura Main Road, Bengaluru – 560119
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND
MACHINE LEARNING
2024-2025/ EVEN SEM
REPORT
on
“Object-Oriented Refactoring and Enhancement of a Procedural
Banking System in Python”
As a part of Comprehensive Continuous Assessment
Submitted by,
Himanshu D Kolchar
(BRANCH/SECTION): Mechanical
Submitted to
Asst.Prof. Sowmya K
Assistant Professor, Department of AI & ML
Banking Application Procedure Oriented
# Global list to store account information
accounts = []
# Global variable for auto-incrementing account numbers
next_account_number = 1001 # Starting account number
# Function to create a new account
def create_account():
global next_account_number
acc_no = str(next_account_number)
name = input("Enter Account Holder Name: ")
try:
balance = float(input("Enter Initial Deposit: "))
except ValueError:
print("Invalid amount! Please enter a numeric value.\n")
return
account = [acc_no, name, balance]
accounts.append(account)
print(f"Account created successfully! Your Account Number is:
{acc_no}\n")
next_account_number += 1
# Function to find account index by account number
def find_account_index(acc_no):
for i in range(len(accounts)):
if accounts[i][0] == acc_no:
return i
return -1
# Function to deposit amount
def deposit():
acc_no = input("Enter Account Number for Deposit: ")
idx = find_account_index(acc_no)
if idx != -1:
try:
amount = float(input("Enter amount to deposit: ")) accounts[idx]
[2] += amount
print(f"₹{amount} deposited. New balance:
₹{accounts[idx][2]}\n")
except ValueError:
print("Invalid amount!\n")
else:
print("Account not found!\n")
# Function to withdraw amount
def withdraw():
acc_no = input("Enter Account Number for Withdrawal: ")
idx = find_account_index(acc_no)
if idx != -1:
try:
amount = float(input("Enter amount to withdraw: "))
if amount <= accounts[idx][2]:
accounts[idx][2] -= amount
print(f"₹{amount} withdrawn. Remaining balance:
₹{accounts[idx][2]}\n")
else:
print("Insufficient balance!\n")
except ValueError:
print("Invalid amount!\n")
else:
print("Account not found!\n")
# Function to check balance
def check_balance():
acc_no = input("Enter Account Number to Check Balance: ")
idx = find_account_index(acc_no)
if idx != -1:
print(f"Current balance for account {acc_no} is
₹{accounts[idx][2]}\n")
else:
print("Account not found!\n")
# Function to close account
def close_account():
acc_no = input("Enter Account Number to Close: ")
idx = find_account_index(acc_no)
if idx != -1:
accounts.pop(idx)
print(f"Account {acc_no} closed successfully.\n")
else:
print("Account not found!\n")
# Function to display all accounts sorted by account number
def display_all_accounts():
if not accounts:
print("No accounts to display.\n")
else:
print("All Accounts (sorted by Account Number):")
sorted_accs = sorted(accounts, key=lambda acc: int(acc[0]))
for acc in sorted_accs:
print(f"Account No: {acc[0]}, Name: {acc[1]}, Balance:
₹{acc[2]}")
print()
# Main menu
def main():
while True:
print("===== BANKING SYSTEM MENU =====")
print("1. Create Account")
print("2. Deposit")
print("3. Withdraw")
print("4. Check Balance")
print("5. Close Account")
print("6. Display All Accounts")
print("7. Exit")
choice = input("Enter your choice (1-7): ")
if choice == '1':
create_account()
elif choice == '2':
deposit()
elif choice == '3':
withdraw()
elif choice == '4':
check_balance()
elif choice == '5':
close_account()
elif choice == '6':
display_all_accounts()
elif choice == '7':
print("Exiting... Thank you for using our banking system.")
break
else:
print("Invalid choice! Please try again.\n")
# Run the application
main()
Object-Oriented Code:
class Account:
accounts = []
next_account_number = 1001
def init (self, name, balance):
self.acc_no = str(Account.next_account_number)
self.name = name
self.balance = balance
Account.next_account_number += 1
Account.accounts.append(self)
def find_account_by_number(acc_no):
for acc in Account.accounts:
if acc.acc_no == acc_no:
return acc
return None
def create_account():
name = input("Enter Account Holder Name: ")
try:
balance = float(input("Enter Initial Deposit: "))
new_acc = Account(name, balance)
print(f"Account created successfully! Your Account Number is:
{new_acc.acc_no}\n")
except ValueError:
print("Invalid amount entered.\n")
@staticmethod
def deposit():
acc_no = input("Enter Account Number for Deposit: ")
acc = Account.find_account_by_number(acc_no)
if acc:
try:
amount = float(input("Enter amount to deposit: "))
acc.balance += amount
print(f"₹{amount} deposited. New balance:
₹{acc.balance}\n")
except ValueError:
print("Invalid amount.\n")
else:
print("Account not found!\n")
@staticmethod
def withdraw():
acc_no = input("Enter Account Number for Withdrawal: ")
acc = Account.find_account_by_number(acc_no)
if acc:
try:
amount = float(input("Enter amount to withdraw: "))
if amount <= acc.balance:
acc.balance -= amount
print(f"₹{amount} withdrawn. Remaining balance:
₹{acc.balance}\n")
else:
print("Insufficient balance!\n")
except ValueError:
print("Invalid amount.\n")
else:
print("Account not found!\n")
@staticmethod
def check_balance():
acc_no = input("Enter Account Number to Check Balance: ")
acc = Account.find_account_by_number(acc_no)
if acc:
print(f"Current balance for account {acc.acc_no} is
₹{acc.balance}\n")
else:
print("Account not found!\n")
@staticmethod
def close_account():
acc_no = input("Enter Account Number to Close: ")
acc = Account.find_account_by_number(acc_no)
if acc:
Account.accounts.remove(acc)
print(f"Account {acc_no} closed successfully.\n")
else:
print("Account not found!\n")
@staticmethod
def display_all_accounts():
if not Account.accounts:
print("No accounts to display.\n")
else:
print("All Accounts (sorted by Account Number):")
sorted_accounts = sorted(Account.accounts, key=lambda a:
int(a.acc_no))
for acc in sorted_accounts:
print(f"Account No: {acc.acc_no}, Name: {acc.name},
Balance: ₹{acc.balance}")
print()
def main():
while True:
print("===== BANKING SYSTEM MENU =====")
print("1. Create Account")
print("2. Deposit")
print("3. Withdraw")
print("4. Check Balance")
print("5. Close Account")
print("6. Display All Accounts")
print("7. Exit")
choice = input("Enter your choice (1-7): ")
if choice == '1':
Account.create_account()
elif choice == '2':
Account.deposit()
elif choice == '3':
Account.withdraw()
elif choice == '4':
Account.check_balance()
elif choice == '5':
Account.close_account()
elif choice == '6':
Account.display_all_accounts()
elif choice == '7':
print("Exiting... Thank you for using our banking system.")
break
else:
print("Invalid choice! Please try again.\n")
# Run the program
main()
OBJECT ORIENTED PROGRAM BY IMPLEMENTATION OF SEARCH BY ACCOUNT NAME
class Account:
def init (self, acc_no, name, balance):
self.acc_no = acc_no
self.name = name
self.balance = balance
def deposit(self, amount):
self.balance += amount
print(f"₹{amount} deposited. New balance: ₹{self.balance}\n")
def withdraw(self, amount):
if amount <= self.balance:
self.balance -= amount
print(f"₹{amount} withdrawn. Remaining balance:
₹{self.balance}\n")
else:
print("Insufficient balance!\n")
def check_balance(self):
print(f"Current balance for account {self.acc_no} is
₹{self.balance}\n")
class Bank:
def init (self):
self.accounts = []
self.next_account_number = 1001
def create_account(self):
name = input("Enter Account Holder Name: ")
try:
balance = float(input("Enter Initial Deposit: "))
except ValueError:
print("Invalid input for balance!\n")
return
acc_no = str(self.next_account_number)
account = Account(acc_no, name, balance)
self.accounts.append(account)
self.next_account_number += 1
print(f"Account created successfully! Your Account Number is:
{acc_no}\n")
def find_account_by_number(self, acc_no):
for acc in self.accounts:
if acc.acc_no == acc_no:
return acc
return None
def find_accounts_by_name(self, name):
return [acc for acc in self.accounts if acc.name.lower() ==
name.lower()]
def deposit_to_account(self):
acc_no = input("Enter Account Number for Deposit: ")
acc = self.find_account_by_number(acc_no)
if acc:
try:
amount = float(input("Enter amount to deposit: "))
acc.deposit(amount)
except ValueError:
print("Invalid amount!\n")
else:
print("Account not found!\n")
def withdraw_from_account(self):
acc_no = input("Enter Account Number for Withdrawal: ")
acc = self.find_account_by_number(acc_no)
if acc:
try:
amount = float(input("Enter amount to withdraw: "))
acc.withdraw(amount)
except ValueError:
print("Invalid amount!\n")
else:
print("Account not found!\n")
def check_account_balance(self):
acc_no = input("Enter Account Number to Check Balance: ")
acc = self.find_account_by_number(acc_no)
if acc:
acc.check_balance()
else:
print("Account not found!\n")
def close_account(self):
acc_no = input("Enter Account Number to Close: ")
acc = self.find_account_by_number(acc_no)
if acc:
self.accounts.remove(acc)
print(f"Account {acc_no} closed successfully.\n")
else:
print("Account not found!\n")
def search_account_by_name(self):
name = input("Enter Account Holder Name to Search: ")
results = self.find_accounts_by_name(name)
if results:
print(f"Found {len(results)} account(s) with name '{name}':")
for acc in results:
print(f"Account No: {acc.acc_no}, Name: {acc.name},
Balance: ₹{acc.balance}")
print()
else:
print("No account found with that name.\n")
def main():
bank = Bank()
while True:
print("===== BANKING SYSTEM MENU =====")
print("1. Create Account")
print("2. Deposit")
print("3. Withdraw")
print("4. Check Balance")
print("5. Close Account")
print("6. Search Account by Name")
print("7. Exit")
choice = input("Enter your choice (1-7): ")
if choice == '1':
bank.create_account()
elif choice == '2':
bank.deposit_to_account()
elif choice == '3':
bank.withdraw_from_account()
elif choice == '4':
bank.check_account_balance()
elif choice == '5':
bank.close_account()
elif choice == '6':
bank.search_account_by_name()
elif choice == '7':
print("Exiting... Thank you for using our banking system.")
break
else:
print("Invalid choice! Please try again.\n")
# Run the
program main()
PROS/CONS PROGRAM ORIENTED CONCEPT TO OBJECT
ORIENTED CONCEPT:
Pros of Converting POP to OOP:
Advantage Explanation
1. Better Code Organization In OOP, related data and methods are grouped inside
classes, making the code easier to read, debug, and manage.
2. Reusability OOP allows you to reuse classes and methods in
multiple programs without rewriting the logic.
3. Scalability Easy to add new features (like interest calculation or
password protection) by just extending classes.
4. Encapsulation Data (like balance) is hidden inside objects and
accessed only through methods. This protects data integrity.
5. Real-world Modeling Objects (like Account, Customer) directly represent
real-world entities, making it intuitive.
6. Maintainability OOP code is modular, so changes in one class don’t
break the whole system.
7. Code Reusability Through
Inheritance You can create new classes (e.g., Savings Account) from existing ones.
Cons of Converting to OOP:
Disadvantage Explanation
1. More Complex for Small
Tasks 2. More Code Overhead For small, simple programs, POP is quicker and easier to write.
You often write more lines (classes, objects,
methods) compared to straightforward POP code.
3. Requires OOP Knowledge 4. Slightly Slower
for Simple Programs
5. Debugging Can Be Tricky Beginners need to understand objects,
methods, constructors, and inheritance.
OOP uses more memory and processing compared to POP in
small-scale applications.
Tracking bugs in class hierarchies or object interactions
may take more Time.
Student USN: 1BY24ME020 FACULTY INCHARGE
NAME: Himanshu D Kolchar Asst. Prof. Sowmya K
2 SEM,MECH
Signature