-
Notifications
You must be signed in to change notification settings - Fork 1
/
PoC1_1q10_BankAccount.py
88 lines (80 loc) · 2.25 KB
/
PoC1_1q10_BankAccount.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class BankAccount:
""" Class definition modeling the behavior of a simple bank account """
def __init__(self, initial_balance):
"""Creates an account with the given balance."""
self.balance = initial_balance
self.fee = 0
def deposit(self, amount):
"""Deposits the amount into the account."""
self.balance += amount
def withdraw(self, amount):
"""
Withdraws the amount from the account. Each withdrawal resulting
in a negative balance also deducts a penalty fee of 5 dollars
from the balance.
"""
self.balance -= amount
if self.balance < 0 :
self.balance -= 5
self.fee += 5
def get_balance(self):
"""Returns the current balance in the account."""
return self.balance
def get_fees(self):
"""Returns the total fees ever deducted from the account."""
return self.fee
# Test 1
my_account = BankAccount(10)
my_account.withdraw(15)
my_account.deposit(20)
print "TEST 1"
print "Balance =", my_account.get_balance()
print "Fee = ", my_account.get_fees()
print
# Test 2
my_account = BankAccount(10)
my_account.withdraw(5)
my_account.deposit(10)
my_account.withdraw(5)
my_account.withdraw(15)
my_account.deposit(20)
my_account.withdraw(5)
my_account.deposit(10)
my_account.deposit(20)
my_account.withdraw(15)
my_account.deposit(30)
my_account.withdraw(10)
my_account.withdraw(15)
my_account.deposit(10)
my_account.withdraw(50)
my_account.deposit(30)
my_account.withdraw(15)
my_account.deposit(10)
my_account.withdraw(5)
my_account.deposit(20)
my_account.withdraw(15)
my_account.deposit(10)
my_account.deposit(30)
my_account.withdraw(25)
my_account.withdraw(5)
my_account.deposit(10)
my_account.withdraw(15)
my_account.deposit(10)
my_account.withdraw(10)
my_account.withdraw(15)
my_account.deposit(10)
my_account.deposit(30)
my_account.withdraw(25)
my_account.withdraw(10)
my_account.deposit(20)
my_account.deposit(10)
my_account.withdraw(5)
my_account.withdraw(15)
my_account.deposit(10)
my_account.withdraw(5)
my_account.withdraw(15)
my_account.deposit(10)
my_account.withdraw(5)
print "TEST 2"
print "Balance =", my_account.get_balance()
print "Fee = ", my_account.get_fees()