-
Notifications
You must be signed in to change notification settings - Fork 1
/
banks.py
40 lines (31 loc) · 1.15 KB
/
banks.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
36
37
38
39
40
class BankAccount:
def __init__(self):
self.balance = 0
def withdraw(self, amount):
self.balance -= amount
return self.balance
def deposit(self, amount):
self.balance += amount
return self.balance
class MinimumBalanceAccount(BankAccount):
def __init__(self, minimum_balance):
BankAccount.__init__(self)
self.minimum_balance = minimum_balance
def withdraw(self, amount):
if self.balance - amount < self.minimum_balance:
print('Sorry, minimum balance must be maintained.')
else:
BankAccount.withdraw(self, amount)
class BlockedAccount(MinimumBalanceAccount):
"""Shitty student account"""
def __init__(self, starting_balance):
super().__init__(0)
min_amount = 9000
if starting_balance < min_amount:
raise ValueError("Need at least {}".format(min_amount))
self.balance = starting_balance
self.monthly_outgoing = 0
def withdraw(self, amount):
if amount + self.monthly_outgoing > 700:
raise ValueError("Exceeded monthly withdrawal limit")
super().withdraw(amount)