Blessing988

Untitled

Apr 6th, 2020
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.70 KB | None | 0 0
  1. from random import randint
  2. from abc import ABCMeta, abstractmethod
  3.  
  4. class Account(metaclass = ABCMeta):
  5.     @abstractmethod
  6.     def createAccount():
  7.         return 0
  8.     @abstractmethod
  9.     def authenticate():
  10.         return 0
  11.     @abstractmethod
  12.     def withdraw():
  13.         return 0
  14.     @abstractmethod
  15.     def deposit():
  16.         return 0
  17.     @abstractmethod
  18.     def displayBalance():
  19.         return 0
  20.    
  21. class SavingsAccount(Account):
  22.     def __init__(self):
  23.         self.savingsAccounts= {}
  24.  
  25.     def createAccount(self, name,initialDeposit):
  26.         print( )
  27.         self.accountNumber = randint(10000, 99999)
  28.         self.savingsAccounts[self.accountNumber]= [name, initialDeposit]
  29.         print("Account creation has been succesful. Your account number is ", self.accountNumber)
  30.         print( )
  31.     def authenticate(self, name, accountNumber):
  32.        
  33.         if accountNumber in self.savingsAccounts.keys():
  34.             if self.savingsAccounts[accountNumber][0] ==name:
  35.                 print("Authentication Successful")
  36.                 self.accountNumber = accountNumber
  37.                 return True
  38.             else:
  39.                 print("Authentication Failed")
  40.                 return False
  41.         else:
  42.             print("Authentication Failed")
  43.             return False
  44.         print( )
  45.                
  46.     def withdraw(self,withdrawalAccount):
  47.         print( )
  48.         if withdrawalAmount > self.savingsAccounts[self.accountNumber][1]:
  49.             print("Insufficient balance")
  50.         else:
  51.             self.savingsAccounts[self.accountNumber][1] -=withdrawalAmount
  52.             print("Withdrawal was successful")
  53.             self.displayBalance()
  54.         print( )
  55.            
  56.     def deposit(self,depositAmount):
  57.         self.savingsAccounts[self.accountNumber][1] +=depositAmount
  58.         print("Deposit was successful")
  59.         self.displayBalance()
  60.         print( )
  61.        
  62.     def displayBalance(self):
  63.         print("Available balance: ", self.savingsAccount[accountNumber][1])
  64.  
  65. savingsAccount = SavingsAccount()
  66. while True:
  67.     print( )
  68.     print("Enter 1 to create a new account")
  69.     print("Enter 2 to access an existing account")
  70.     print("Enter 3 to exit")
  71.     print( )
  72.     userChoice = int(input())
  73.     if userChoice == 1:
  74.         print( )
  75.         print("Enter your name: ")
  76.         name = input( )
  77.         print("Enter the initial deposit: ")
  78.         deposit = float(input( ))
  79.         savingsAccount.createAccount(name, deposit)
  80.     elif userChoice ==2:
  81.         print("Enter your name: ")
  82.         name = input()
  83.         print("Enter your account number: ")
  84.         accountNumber = int(input())
  85.  
  86.         aunthentication = savingsAccount.authenticate(name, accountNumber)
  87.         if authentication is True:
  88.             while True:
  89.                 print("Enter 1 to withdraw")
  90.                 print("Enter 2 to deposit")
  91.                 print("Enter 3 to display available balance")
  92.                 print("Enter 4 to go back to the previous menu")
  93.                 userChoice = int(input())
  94.                 if userChoice == 1:
  95.                     print("Enter a withdrawal amount")
  96.                     withdrawalAmount = int(input())
  97.                     savingsAccount.withdraw(withdrawalAmount)
  98.                 elif userChoice ==2:
  99.                     print("Enter an amount to be deposited")
  100.                     depositAmount = int(input())
  101.                     savingsAccount.deposit(depositAmount)
  102.                 elif userChoice ==3:
  103.                     savingsAccount.displayBalance( )
  104.                 elif userChoice ==4:
  105.                     break
  106.     elif userChoice ==3:
  107.         quit()
Advertisement
Add Comment
Please, Sign In to add comment