Advertisement
Shahar_Goldenberg

Bank

Sep 15th, 2022 (edited)
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.13 KB | None | 0 0
  1. import random
  2.  
  3. class BankingSystem:
  4.     def __init__(self):
  5.         self.bankingAsystem = {"12345": ["Shola", 100], "10002": ["Nadav", 200], "10003": ["MOhamad", 10]}
  6.  
  7.     def createNewAccount(self):
  8.         name = input("Enter your name: ")
  9.         initialDeposit = float(input("How much money would you like to deposit: "))
  10.  
  11.         while True:
  12.             accessNumber = random.randint(00000, 99999)
  13.             if accessNumber not in self.bankingAsystem.keys():
  14.                 self.bankingAsystem[accessNumber] = [name, initialDeposit]
  15.                 break
  16.  
  17.         print("your account number is {} \n".format(accessNumber))
  18.  
  19.     def accessExistingAccount(self):
  20.         while True:
  21.             name = input("Enter your name: ")
  22.             accountNumber = input("Enter your account number: ")
  23.  
  24.             if accountNumber not in self.bankingAsystem.keys():
  25.                 print("Username or password incorrect\n")
  26.  
  27.             elif self.bankingAsystem[accountNumber][0] == name:
  28.                 while True:
  29.                     print("\n 1. Withdraw money\n \
  30. 2. Deposit money\n \
  31. 3. View your available balance\n \
  32. 4. Exit your account\n")
  33.                     userSecondChoise = int(input())
  34.  
  35.                     if userSecondChoise == 1:
  36.                         while True:
  37.                             moneyWithdraw = float(input("you have {} $,How much money would you like to withdraw money:  ".format(self.bankingAsystem[accountNumber][1])))
  38.                             if self.bankingAsystem[accountNumber][1] > moneyWithdraw:
  39.                                 self.bankingAsystem[accountNumber][1] -= moneyWithdraw
  40.                                 print("now you have {} $ in your account\n".format(self.bankingAsystem[accountNumber][1]))
  41.                                 break
  42.                             else:
  43.                                 print("you don't have enough money\n")
  44.  
  45.                     elif userSecondChoise == 2:
  46.                         while True:
  47.                             depositMoney = float(input("How much money will you want to add to your account: "))
  48.                             if depositMoney >= 0:
  49.                                 self.bankingAsystem[accountNumber][1] += depositMoney
  50.                                 print("now you have {} $ in your account".format(self.bankingAsystem[accountNumber][1]))
  51.                                 break
  52.                             else:
  53.                                 print("Error! You tried to add {} $ to your account\n".format(depositMoney))
  54.  
  55.                     elif userSecondChoise == 3:
  56.                         print("you have {} $ in your account\n".format(self.bankingAsystem[accountNumber][1]))
  57.  
  58.                     elif userSecondChoise == 4:
  59.                         break
  60.  
  61. bankingAsystem = BankingSystem()
  62.  
  63. while True:
  64.     print("\n 1. Create a new account\n \
  65. 2. Access an existing account\n \
  66. 3. Quit\n")
  67.     userChoise = int(input())
  68.  
  69.     if userChoise == 1:
  70.         bankingAsystem.createNewAccount()
  71.  
  72.     elif userChoise == 2:
  73.         bankingAsystem.accessExistingAccount()
  74.  
  75.     elif userChoise == 3:
  76.         quit()
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement