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

Bank Management Coading

This document outlines a simple banking system implemented in Python. It allows users to create accounts, deposit and withdraw money, and check their balance, while saving data to a JSON file. The program features a menu-driven interface for user interaction.

Uploaded by

Abhineet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Bank Management Coading

This document outlines a simple banking system implemented in Python. It allows users to create accounts, deposit and withdraw money, and check their balance, while saving data to a JSON file. The program features a menu-driven interface for user interaction.

Uploaded by

Abhineet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import json import os

DATA_FILE = "bank_data.json"

Load existing data or create new


file
if [Link](DATA_FILE): with open(DATA_FILE, "r") as f: accounts =
[Link](f) else: accounts = {}

def save_data(): with open(DATA_FILE, "w") as f: [Link](accounts, f)

def create_account(): name = input("Enter your name: ") if name in


accounts: print("Account already exists.") return accounts[name] =
{"balance": 0} save_data() print(f"Account created for {name}.")

def deposit(): name = input("Enter your name: ") if name not in accounts:
print("Account not found.") return amount = float(input("Enter amount to
deposit: ")) accounts[name]["balance"] += amount save_data() print(f"$
{amount} deposited. New balance: ${accounts[name]['balance']}")

def withdraw(): name = input("Enter your name: ") if name not in accounts:
print("Account not found.") return amount = float(input("Enter amount to
withdraw: ")) if accounts[name]["balance"] >= amount: accounts[name]
["balance"] -= amount save_data() print(f"${amount} withdrawn. Remaining
balance: ${accounts[name]['balance']}") else: print("Insufficient balance.")

def check_balance(): name = input("Enter your name: ") if name not in


accounts: print("Account not found.") return print(f"Current balance: $
{accounts[name]['balance']}")

def menu(): while True: print("\n=== Bank Menu ===") print("1. Create
Account") print("2. Deposit") print("3. Withdraw") print("4. Check Balance")
print("5. Exit") choice = input("Select an option: ")

if choice == "1":
create_account()
elif choice == "2":
deposit()
elif choice == "3":
withdraw()
elif choice == "4":
check_balance()
elif choice == "5":
print("Thank you for using the bank system.")
break
else:
print("Invalid option. Try again.")

Run the program


menu()

You might also like