-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccount.py
35 lines (25 loc) · 813 Bytes
/
Account.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Account:
def __init__(self, is_debit):
self.__is_debit = is_debit
self.__balance = 0
@staticmethod
def open_debit_account():
return Account(True)
@staticmethod
def open_account():
return Account(False)
def get_balance(self):
return self.__balance
def deposit(self, amount):
self.__balance = self.__balance if amount < 0 else self.__balance + amount
def withdraw(self, amount):
if amount < 0:
return
if self.__is_debit and self.get_balance() < amount:
raise InsufficientFundsException()
self.__balance -= amount
class InsufficientFundsException(Exception):
def __init__(self):
super().__init__(self)
def __str__(self):
return 'Account Exception'