-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbank_account.py
More file actions
33 lines (27 loc) · 851 Bytes
/
bank_account.py
File metadata and controls
33 lines (27 loc) · 851 Bytes
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
class MinimumBalanceError(Exception):
pass
class Account:
AccNumber = 1001
def __init__(self, name, balance=1000):
if balance < 1000:
raise MinimumBalanceError('Account Cannot be Created')
self.name = name
self.balance = balance
self.account_number = Account.AccNumber
Account.AccNumber += 1
def deposit(self, amt):
self.balance += amt
def withdraw(self, amt):
if self.balance - amt < 1000:
raise MinimumBalanceError('Amount cannot be withdrawn')
self.balance -= amt
def show_details(self):
print('Account Number', self.account_number)
print('Name', self.name)
print('Balance', self.balance)
a1 = Account('John', 2000)
try:
a1.withdraw(1500)
except MinimumBalanceError as e:
print(e)
a1.show_details()