Blessing988

Untitled

Apr 6th, 2020
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.78 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.                 print( )
  37.                 self.accountNumber = accountNumber
  38.                 return True
  39.            
  40.             else:
  41.                 print("Authentication Failed")
  42.                 return False
  43.         else:
  44.             print("Authentication Failed")
  45.             return False
  46.         print( )
  47.                
  48.     def withdraw(self,withdrawalAccount):
  49.         print( )
  50.         if withdrawalAmount > self.savingsAccounts[self.accountNumber][1]:
  51.             print("Insufficient balance")
  52.         else:
  53.             self.savingsAccounts[self.accountNumber][1] -=withdrawalAmount
  54.             print("Withdrawal was successful")
  55.             self.displayBalance()
  56.         print( )
  57.            
  58.     def deposit(self,depositAmount):
  59.         self.savingsAccounts[self.accountNumber][1] +=depositAmount
  60.         print("Deposit was successful")
  61.         self.displayBalance()
  62.         print( )
  63.        
  64.     def displayBalance(self):
  65.         print( )
  66.         print("Available balance: ", self.savingsAccounts[accountNumber][1])
  67.         print( )
  68.  
  69. savingsAccount = SavingsAccount()
  70. while True:
  71.     print( )
  72.     print("Enter 1 to create a new account")
  73.     print("Enter 2 to access an existing account")
  74.     print("Enter 3 to exit")
  75.     print( )
  76.     userChoice = int(input())
  77.     if userChoice == 1:
  78.         print( )
  79.         print("Enter your name: ")
  80.         name = input( )
  81.         print("Enter the initial deposit: ")
  82.         deposit = float(input( ))
  83.         savingsAccount.createAccount(name, deposit)
  84.     elif userChoice ==2:
  85.         print("Enter your name: ")
  86.         name = input()
  87.         print("Enter your account number: ")
  88.         accountNumber = int(input())
  89.  
  90.         authentication = savingsAccount.authenticate(name, accountNumber)
  91.         if authentication is True:
  92.             while True:
  93.                 print("Enter 1 to withdraw")
  94.                 print("Enter 2 to deposit")
  95.                 print("Enter 3 to display available balance")
  96.                 print("Enter 4 to go back to the previous menu")
  97.                 userChoice = int(input())
  98.                 if userChoice == 1:
  99.                     print("Enter a withdrawal amount")
  100.                     withdrawalAmount = float(input())
  101.                     savingsAccount.withdraw(withdrawalAmount)
  102.                 elif userChoice ==2:
  103.                     print("Enter an amount to be deposited")
  104.                     depositAmount = int(input())
  105.                     savingsAccount.deposit(depositAmount)
  106.                 elif userChoice ==3:
  107.                     savingsAccount.displayBalance( )
  108.                 elif userChoice ==4:
  109.                     break
  110.     elif userChoice ==3:
  111.         quit()
Advertisement
Add Comment
Please, Sign In to add comment