Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Kaizer here. I created a banking system, which allows you to create your own account, withdraw money, input account numbers, initial balance, and so on and so forth.
- # class to represent a bank account
- class Account:
- def __init__(self, acc_number, acc_holder, initial_balance):
- self.account_number = acc_number
- self.account_holder = acc_holder
- self.balance = initial_balance
- # function to find an already existing account number
- def get_account_number(self):
- return self.account_number
- # function to deposit money into the account
- def deposit(self, amount):
- if amount > 0:
- self.balance += amount
- print(f"Deposited: {amount}")
- else:
- print("Invalid deposit amount.")
- # function to withdraw money from the account
- def withdraw(self, amount):
- if amount > 0 and amount <= self.balance:
- self.balance -= amount
- print(f"Withdrew: {amount}")
- else:
- print("Invalid withdrawal amount or insufficient funds.")
- # function to check the account balance
- def get_balance(self):
- return self.balance
- # function to display account details
- def display(self):
- print(f"Account Number: {self.account_number}")
- print(f"Account Holder: {self.account_holder}")
- print(f"Balance: {self.balance}")
- # public Class to manage multiple accounts
- class Bank:
- def __init__(self):
- self.accounts = []
- # function to create a new account
- def create_account(self, acc_number, acc_holder, initial_balance):
- self.accounts.append(Account(acc_number, acc_holder, initial_balance))
- print("Account created successfully.")
- # function to find an account by account number
- def find_account(self, acc_number):
- for account in self.accounts:
- if account.get_account_number() == acc_number:
- return account
- return None
- # function to display all accounts
- def display_all_accounts(self):
- for account in self.accounts:
- account.display()
- print("-------------------")
- def main():
- bank = Bank()
- while True:
- print("1. Create Account")
- print("2. Deposit")
- print("3. Withdraw")
- print("4. Check Balance")
- print("5. Display All Accounts")
- print("6. Exit")
- choice = input("Enter your choice: ")
- if choice == '1':
- acc_number = input("Enter account number: ")
- acc_holder = input("Enter account holder name: ")
- amount = float(input("Enter initial balance: "))
- bank.create_account(acc_number, acc_holder, amount)
- elif choice == '2':
- acc_number = input("Enter account number: ")
- account = bank.find_account(acc_number)
- if account:
- amount = float(input("Enter amount to deposit: "))
- account.deposit(amount)
- else:
- print("Account not found.")
- elif choice == '3':
- acc_number = input("Enter account number: ")
- account = bank.find_account(acc_number)
- if account:
- amount = float(input("Enter amount to withdraw: "))
- account.withdraw(amount)
- else:
- print("Account not found.")
- elif choice == '4':
- acc_number = input("Enter account number: ")
- account = bank.find_account(acc_number)
- if account:
- print(f"Balance: {account.get_balance()}")
- else:
- print("Account not found.")
- elif choice == '5':
- bank.display_all_accounts()
- elif choice == '6':
- print("Exiting...")
- break
- else:
- print("Invalid choice. Please try again.")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement