0% found this document useful (0 votes)
105 views4 pages

Exp 9

This document outlines a Python program that simulates a Bank Account Management System, allowing users to create accounts, deposit and withdraw money, check balances, and delete accounts. The program utilizes a class to manage account data and a dictionary to store multiple accounts, with a menu-driven interface for user interaction. It serves as a demonstration of object-oriented programming concepts and user interaction in Python.

Uploaded by

Deepanshu Fulara
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)
105 views4 pages

Exp 9

This document outlines a Python program that simulates a Bank Account Management System, allowing users to create accounts, deposit and withdraw money, check balances, and delete accounts. The program utilizes a class to manage account data and a dictionary to store multiple accounts, with a menu-driven interface for user interaction. It serves as a demonstration of object-oriented programming concepts and user interaction in Python.

Uploaded by

Deepanshu Fulara
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

EXPERIMENT –9

Aim: Write a program to create a class for bank account in which creating an account,
deposit, withdrawal, check balance and deleting the account functions are present.
Software Used: Spyder.
Theory: This Python program simulates a Bank Account Management System. It allows
users to perform basic operations like creating an account, depositing money, withdrawing
money, checking balance, and deleting an account. The data for each account (account
number, account holder name, and balance) is stored in a BankAccount class. A menu-driven
approach is used to interact with the user and take input for each operation. The program uses
a dictionary to manage multiple accounts, where the account number is the key, and the
BankAccount object is the value.

Source Code:
class BankAccount:
def __init__(self, account_number, account_holder, initial_balance=0):
self.account_number = account_number
self.account_holder = account_holder
self.balance = initial_balance

def deposit(self, amount):


if amount > 0:
self.balance += amount
print(f"₹{amount} deposited successfully. New balance: ₹{self.balance}")
else:
print("Invalid deposit amount.")

def withdraw(self, amount):


if 0 < amount <= self.balance:
self.balance -= amount
print(f"₹{amount} withdrawn successfully. New balance: ₹{self.balance}")
elif amount > self.balance:
print("Insufficient balance.")
else:
print("Invalid withdrawal amount.")

def check_balance(self):
print(f"Current balance: ₹{self.balance}")
# Dictionary to store all bank accounts
accounts = {}
def create_account():
account_number = input("Enter account number: ")
account_holder = input("Enter account holder's name: ")
initial_balance = float(input("Enter initial balance: "))
accounts[account_number] = BankAccount(account_number, account_holder,
initial_balance)
print("Account created successfully.")
def deposit():
account_number = input("Enter account number: ")
if account_number in accounts:
amount = float(input("Enter amount to deposit: "))
accounts[account_number].deposit(amount)
else:
print("Account not found.")
def withdraw():
account_number = input("Enter account number: ")
if account_number in accounts:
amount = float(input("Enter amount to withdraw: "))
accounts[account_number].withdraw(amount)
else:
print("Account not found.")
def check_balance():
account_number = input("Enter account number: ")
if account_number in accounts:
accounts[account_number].check_balance()
else:
print("Account not found.")
def delete_account():
account_number = input("Enter account number to delete: ")
if account_number in accounts:
del accounts[account_number]
print("Account deleted successfully.")
else:
print("Account not found.")

while True:
print("\n--- Bank Account Management ---")
print("1. Create Account")
print("2. Deposit Money")
print("3. Withdraw Money")
print("4. Check Balance")
print("5. Delete Account")
print("6. Exit")
choice = input("Enter your choice: ")
if choice == '1':
create_account()
elif choice == '2':
deposit()
elif choice == '3':
withdraw()
elif choice == '4':
check_balance()
elif choice == '5':
delete_account()
elif choice == '6':
print("Exiting program. Thank you!")
break
else:
print("Invalid choice. Please try again.")

Output:
Conclusion:
This Python program allows users to manage a simple banking system with functionalities
like account creation, deposits, withdrawals, checking balances, and deleting accounts. User
inputs drive the program to perform these tasks interactively. This is a great demonstration of
OOP concepts and user interaction in Python.

You might also like