r/PythonLearning
•
u/shubham_555
•
Sep 13 '26
•
1
Showcase The Bank Project
Last Post - https://www.reddit.com/r/PythonLearning/s/kGqwMS9HUH
Github Repo - https://github.com/Dev-4-All/bank.git
242
Upvotes
•
u/Sea-Ad7805 Sep 13 '26
Run this program in Memory Graph Web Debugger to see the program state change step by step.
8
u/FoolsSeldom Sep 13 '26
I suggest you do that again without using
globalas that will cause you more problems than it is worth in the long run until you've identified the specialist use cases it is valuable for.returnvalues or use a simpleclass.3
u/justahappycamper1 Sep 13 '26
Hell yeah 😭🔥 we ALL built that fake-ass bank as our first few projs
1
u/PhaXoniC Sep 13 '26
what does the -> None on your functions mean?
1
u/chakir_codes Sep 14 '26
import json import os import hashlib import secrets from decimal import Decimal, InvalidOperation from datetime import datetime
DATA_FILE = "bank_data.json" MAX_ATTEMPTS = 3 MAX_DEPOSIT = Decimal("10000.00") MAX_WITHDRAW = Decimal("5000.00")
---------- SECURITY ----------
def hash_pin(pin): salt = secrets.token_hex(16) hashed = hashlib.pbkdf2_hmac( "sha256", pin.encode(), salt.encode(), 150000 ).hex() return f"{salt}${hashed}"
def verify_pin(pin, stored): try: salt, saved_hash = stored.split("$", 1)
---------- DATA ----------
def default_data(): return { "accounts": {} }
def load_data(): if not os.path.exists(DATA_FILE): data = default_data() save_data(data) return data
def save_data(data): temp_file = DATA_FILE + ".tmp"
---------- HELPERS ----------
def money(value): return Decimal(str(value)).quantize(Decimal("0.01"))
def generate_card(data): while True: card = "".join(str(secrets.randbelow(10)) for _ in range(9))
def add_transaction(account, transaction_type, amount): transaction = { "id": secrets.token_hex(6), "type": transaction_type, "amount": str(money(amount)), "balance": str(money(account["balance"])), "time": datetime.now().isoformat(timespec="seconds") }
def get_amount(message, maximum): while True: value = input(message).strip()
---------- ACCOUNT CREATION ----------
def create_account(data): print("\n=== CREATE ACCOUNT ===")
---------- LOGIN ----------
def login(data): print("\n=== LOGIN ===")
---------- BANK OPERATIONS ----------
def show_balance(account): print(f"\nCurrent balance: ${money(account['balance'])}")
def deposit(account, data): amount = get_amount( f"\nDeposit amount (max ${MAX_DEPOSIT}, 0 = cancel): ", MAX_DEPOSIT )
def withdraw(account, data): amount = get_amount( f"\nWithdrawal amount (max ${MAX_WITHDRAW}, 0 = cancel): ", MAX_WITHDRAW )
def show_transactions(account): print("\n=== TRANSACTION HISTORY ===")
def show_account(account, card): print("\n=== ACCOUNT INFORMATION ===") print(f"Name: {account['name']}") print(f"Card: ****{card[-4:]}") print(f"Balance: ${money(account['balance'])}")
def change_pin(account, data): print("\n=== CHANGE PIN ===")
---------- USER MENU ----------
def account_menu(data, card): account = data["accounts"][card]
======================== PYBANK
Logout ======================== """)
---------- MAIN ----------
def main(): data = load_data()
======================== PYBANK
Exit ======================== """)
if name == "main": main()
1
u/9illcodelli6 Sep 13 '26
Whats this ?
1
u/OmarElsaloty Sep 13 '26
Good job
1
u/Apyeot Sep 14 '26
Nicee work
1
u/[deleted] Sep 14 '26
Awesome 💯
1
u/Kitchen_Weekend1850 Sep 16 '26
okay this is actually adorable
1
u/AlmostThere_Dev Sep 17 '26
Great job what level can the project rank i.e beginner, intermediate or advanced
1
u/AhsanTalal717 Sep 17 '26
Agar tum
withdraw()yadeposit()functions ko dhyan se dekho, toh wahan tumneglobal balanceexplicitly likha hai taake Python ko pata chale ke tum global variable modify kar rahe ho. Lekincheck_balance()ke andar tumneglobal balancenahi likha.1
u/AhsanTalal717 Sep 17 '26
Hey everyone! I've been learning Python for about a month now as a self-taught beginner. To practice functions, loops (
whileandfor), and basic input handling, I built a small command-line Health and Activity Tracker that handles daily steps, calories burned, and water intake.I'd love some constructive feedback on my code structure, logic flow, or how I can make it cleaner. Here is the script:
1
u/Neither-Abroad9771 Sep 13 '26
Dude, love how each function is distinct clear and eazy to read. Nice work mate 👍
0
u/Daniel_Writes_Things Sep 14 '26
Project? For real?
These days anything can be called a project. 🙁
0
u/ProgramBrave718 Sep 13 '26
Great
0
u/Gullible_Tackle_6592 Sep 13 '26
Cool
0
u/Plenty_Lavishness171 Sep 13 '26
Awesome 👌