|
| 1 | +class Account: |
| 2 | + counter = 0 |
| 3 | + |
| 4 | + def __init__(self,balance=0): |
| 5 | + self.__balance = balance # A double underscore encrypts the object from user |
| 6 | + self.id = Account.counter # Known as Name mangling |
| 7 | + Account.counter += 1 |
| 8 | + self.trans = 0 |
| 9 | + self.max_trans = 2 |
| 10 | + |
| 11 | + def deposit(self,amount): |
| 12 | + if amount > 0 and self.trans < self.max_trans : |
| 13 | + self.__balance += amount |
| 14 | + self.trans += 1 |
| 15 | + |
| 16 | + |
| 17 | + def get_balance(self): |
| 18 | + return self.__balance |
| 19 | + |
| 20 | + |
| 21 | + def deposit_interest(self,amount): |
| 22 | + self.__balance += amount |
| 23 | + |
| 24 | + |
| 25 | + def withdraw(self,amount): |
| 26 | + if amount > 0 and amount <= self.__balance and self.trans < self.max_trans: |
| 27 | + self.__balance -= amount |
| 28 | + self.trans += 1 |
| 29 | + else: |
| 30 | + print('Invalid transaction') |
| 31 | + |
| 32 | + def __str__(self): |
| 33 | + return f'The Account number 52986600{Account.counter} has available balance of {self.get_balance()} Rs. ' |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +print('For Savings Account type - SA') |
| 38 | +print('For Current Account type - CA') |
| 39 | +access = input('Which account do you want to access? Type here -> ') |
| 40 | + |
| 41 | +if access == 'SA': |
| 42 | + class SavingsAccount(Account): |
| 43 | + def get_interest(self): |
| 44 | + return self.deposit_interest(self.get_balance() * 0.06) |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + print('Welcome customer') |
| 49 | + sa1 = SavingsAccount(int(input('Enter opening balance: '))) |
| 50 | + print('For deposit press D') |
| 51 | + print('For Withdrawal press W') |
| 52 | + option = input('Option: ') |
| 53 | + if option == 'D': |
| 54 | + sa1.deposit(int(input('Enter the amount to be deposited: '))) |
| 55 | + elif option == 'W': |
| 56 | + sa1.withdraw(int(input('Enter the amount withdrawn: '))) |
| 57 | + else: |
| 58 | + print('Try again') |
| 59 | + print('For deposit press D') |
| 60 | + print('For Withdrawal press W') |
| 61 | + option = input('Option: ') |
| 62 | + if option == 'D': |
| 63 | + sa1.deposit(int(input('Enter the amount to be deposited: '))) |
| 64 | + elif option == 'W': |
| 65 | + sa1.withdraw(int(input('Enter the amount withdrawn: '))) |
| 66 | + else: |
| 67 | + print('Last Try! Fill carefully!') |
| 68 | + print('For deposit press D') |
| 69 | + print('For Withdrawal press W') |
| 70 | + option = input('Option: ') |
| 71 | + if option == 'D': |
| 72 | + sa1.deposit(int(input('Enter the amount to be deposited: '))) |
| 73 | + elif option == 'W': |
| 74 | + sa1.withdraw(int(input('Enter the amount withdrawn: '))) |
| 75 | + else: |
| 76 | + print('Transaction cancelled.(INFO : Invalid Option) ') |
| 77 | + |
| 78 | + print(sa1) |
| 79 | + print('Thank You! Visit Again') |
| 80 | + print('-X' * 30 + '-') |
| 81 | + |
| 82 | +elif access == 'CA': |
| 83 | + class CurrentAccount(Account): |
| 84 | + |
| 85 | + def __init__(self): |
| 86 | + super() # It helps in referencing to the super class of the sub class being used. |
| 87 | + self.max_trans = 3 |
| 88 | + |
| 89 | + |
| 90 | + print('Welcome customer') |
| 91 | + ca1 = Account(int(input('Enter the amount: '))) |
| 92 | + print('For deposit press D') |
| 93 | + print('For Withdrawal press W') |
| 94 | + option = input('Option: ') |
| 95 | + if option == 'D': |
| 96 | + ca1.deposit(int(input('Enter the amount to be deposited: '))) |
| 97 | + elif option == 'W': |
| 98 | + ca1.withdraw(int(input('Enter the amount withdrawn: '))) |
| 99 | + else: |
| 100 | + print('Try again') |
| 101 | + print('For deposit press D') |
| 102 | + print('For Withdrawal press W') |
| 103 | + option = input('Option: ') |
| 104 | + if option == 'D': |
| 105 | + ca1.deposit(int(input('Enter the amount to be deposited: '))) |
| 106 | + elif option == 'W': |
| 107 | + ca1.withdraw(int(input('Enter the amount withdrawn: '))) |
| 108 | + else: |
| 109 | + print('Last Try! Fill carefully!') |
| 110 | + print('For deposit press D') |
| 111 | + print('For Withdrawal press W') |
| 112 | + option = input('Option: ') |
| 113 | + if option == 'D': |
| 114 | + ca1.deposit(int(input('Enter the amount to be deposited: '))) |
| 115 | + elif option == 'W': |
| 116 | + ca1.withdraw(int(input('Enter the amount withdrawn: '))) |
| 117 | + else: |
| 118 | + print('Transaction cancelled.(INFO : Invalid Option) ') |
| 119 | + |
| 120 | + print(ca1) |
| 121 | + print('Thank You! Visit Again') |
| 122 | + print('-X' * 30 + '-') |
| 123 | + |
| 124 | +else: |
| 125 | + print('Invalid option! Try Again') |
0 commit comments