BehchetMehmed

Enhanced Bank Account Management System

Jan 24th, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.85 KB | Source Code | 0 0
  1. # Enhanced Bank Account Management System
  2.  
  3. # 🏦 Data Structures to Store Information
  4. account_holders = []  # Account names
  5. balances = []         # Account balances
  6. transaction_histories = []  # Account transaction logs
  7. loans = []            # Account loan details
  8.  
  9. MAX_LOAN_AMOUNT = 10000
  10. INTEREST_RATE = 0.03
  11. def display_menu():
  12.     """Main menu for banking system."""
  13.     print("\n🌟 Welcome to Enhanced Bank System 🌟")
  14.     print("1️⃣ Create Account")
  15.     print("2️⃣ Deposit Money")
  16.     print("3️⃣ Withdraw Money")
  17.     print("4️⃣ Check Balance")
  18.     print("5️⃣ List All Accounts")
  19.     print("6️⃣ Transfer Funds")
  20.     print("7️⃣ View Transaction History")
  21.     print("8️⃣ Apply for Loan")
  22.     print("9️⃣ Repay Loan")
  23.     print("🔟 Identify Credit Card Type")
  24.     print("0️⃣ Exit")
  25.  
  26. def create_account():
  27.     # TODO: Add logic
  28.     """Create a new account."""
  29.     counter = -1
  30.     users_name = input("Please import your Username: ")
  31.     account_holders.append(users_name)
  32.     balances.append(0)
  33.     loans.append(0)
  34.     for i in balances:
  35.         counter += 1
  36.     print(f"This is your special number you need for further operations:  {counter}")
  37.     print(account_holders)
  38.     print(loans)
  39.     print(balances)
  40.  
  41.  
  42. def deposit():
  43.     account_balance = 0
  44.     """Deposit money into an account."""
  45.     user_name = input("Please import your username: ")
  46.     special_num = int(input("Please import your special number: "))
  47.     if user_name in account_holders:
  48.         amount = int(input("Please write amount of money: "))
  49.         balances[special_num] += amount
  50.     else:
  51.         print("Incorrect username or special num!")
  52.     print(f"Balance: {balances[special_num]}")
  53.  
  54. def withdraw():
  55.     """Withdraw money from an account."""
  56.     # TODO: Add logic
  57.     user_name = input("Please import your username: ")
  58.     special_num = int(input("Please import your special number: "))
  59.     if user_name in account_holders:
  60.         amount = int(input("Please write amount of money: "))
  61.         balances[special_num] -= amount
  62.     else:
  63.         print("Incorrect username or special num!")
  64.     print(f"Balance: {balances[special_num]}")
  65.  
  66. def check_balance():
  67.     """Check balance of an account."""
  68.       # TODO: Add logic
  69.     username = input("To check your balance please import your username: ")
  70.     special_num = int(input("Please import your special number: "))
  71.     if username in account_holders:
  72.         print(f"Balance: {balances[special_num]}")
  73.     else:
  74.         print("Incorrect username or special num!")
  75.  
  76. def list_accounts():
  77.     """List all account holders and details."""
  78.     # TODO: Add logic
  79.     print(f"Account holders: {account_holders}")
  80.     print(f"Account balances: {balances}")
  81.     print(f"Loans: {loans}")
  82.  
  83. def transfer_funds():
  84.     """Transfer funds between two accounts."""
  85.     # TODO: Add logic
  86.     senders_username = input("Please import your username: ")
  87.     senders_special_num = int(input("Please import your special num: "))
  88.     receivers_username = input("Please import receivers username: ")
  89.     receivers_special_num = int(input("Please import receivers special num: "))
  90.     amount = 0
  91.     if senders_username in account_holders and receivers_username in account_holders:
  92.         amount = int(input("Please import the amount you want to transfer: "))
  93.         if amount > balances[senders_special_num]:
  94.             print("Non-sufficient funds!")
  95.  
  96.         else:
  97.             balances[senders_special_num] -= amount
  98.             balances[receivers_special_num] += amount
  99.     else:
  100.         print("Incorrect username or special num!")
  101.     operation = f"Sender: {senders_username} -> Receiver: {receivers_username} Amount: {amount}"
  102.     transaction_histories.append(operation)
  103.     print(balances)
  104. def view_transaction_history():
  105.     """View transactions for an account."""
  106.     # TODO: Add logic
  107.     print(transaction_histories)
  108.  
  109.  
  110. def apply_for_loan():
  111.     """Allow user to apply for a loan."""
  112.     # TODO: Add logic
  113.     username = input("Please import your username: ")
  114.     special_num = int(input("Please import your special num: "))
  115.     if username in account_holders:
  116.         loan_amount = int(input("How much would you like to be loaned? Keep in mind that the maximum amount that we can provide is 10000: "))
  117.         if loan_amount > MAX_LOAN_AMOUNT:
  118.             print("Sorry, but your loan is not approved")
  119.         else:
  120.             years = int(input("In how many years would you like to pay it back: "))  # years of the loan
  121.             print("Perfect the money is in your balance!")
  122.             balances[special_num] += loan_amount
  123.             interest = loan_amount * INTEREST_RATE * years
  124.             loans[special_num] += interest + loan_amount
  125.     else:
  126.         print("Incorrect username or special num!")
  127.  
  128.  
  129. def repay_loan():
  130.     """Allow user to repay a loan."""
  131.     # TODO: Add logic
  132.     username = input("Please import your username: ")
  133.     special_num = int(input("Please import your special num: "))
  134.     if username in account_holders:
  135.         amount = int(input("How much would you like to pay: "))
  136.         balances[special_num] -= amount
  137.         loans[special_num] -= amount
  138.         print(f"Your loan balance is: {loans[special_num]}")
  139.     else:
  140.         print("Incorrect username or special num!")
  141.  
  142. def identify_card_type():
  143.     """Identify type of credit card."""
  144.     # TODO: Add logic
  145.     card_number = int(input("Please import your card number: "))
  146.     card_num_as_str = str(card_number)
  147.     card_type = ""
  148.     if len(card_num_as_str) == 16:
  149.         for i in range(len(card_num_as_str)):
  150.             if card_num_as_str[0] == "4":
  151.                 card_type = "Visa"
  152.             elif card_num_as_str[0] == "2" or card_num_as_str[0] == "5":
  153.                 card_type = "Mastercard"
  154.             elif card_num_as_str[0] == "3":
  155.                 card_type = "American Express"
  156.     else:
  157.         print("Invalid card number!")
  158.     print(f"Card type: {card_type}")
  159. def main():
  160.     """Run the banking system."""
  161.     while True:
  162.         display_menu()
  163.         choice = int(input("Enter your choice: "))
  164.         # Map choices to functions
  165.         if choice == 1:
  166.             create_account()
  167.         elif choice == 2:
  168.             deposit()
  169.         elif choice == 3:
  170.             withdraw()
  171.         elif choice == 4:
  172.             check_balance()
  173.         elif choice == 5:
  174.             list_accounts()
  175.         elif choice == 6:
  176.             transfer_funds()
  177.         elif choice == 7:
  178.             view_transaction_history()
  179.         elif choice == 8:
  180.             apply_for_loan()
  181.         elif choice == 9:
  182.             repay_loan()
  183.         elif choice == 10:
  184.             identify_card_type()
  185.         elif choice == 0:
  186.             print("Goodbye! 👋")
  187.             break
  188.         else:
  189.             print("❌ Invalid choice. Try again!")
  190.  
  191. if __name__ == "__main__":
  192.     main()
Advertisement
Add Comment
Please, Sign In to add comment