Skip to content

Commit dd966d7

Browse files
author
tiagomestreteixeira
committed
Indented the code of the lecture 13
1 parent ffe8da3 commit dd966d7

File tree

2 files changed

+187
-193
lines changed

2 files changed

+187
-193
lines changed

week7/lecture13/retirement.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,60 @@
66
"""
77

88
import pylab as plt
9+
plt.interactive(False)
10+
911

1012
def retire(monthly, rate, terms):
1113
savings = [0]
1214
base = [0]
13-
monthlyRate = rate/12
15+
monthlyRate = rate / 12
1416
for i in range(terms):
1517
base += [i]
16-
savings += [savings[-1]*(1 + monthlyRate) + monthly]
18+
savings += [savings[-1] * (1 + monthlyRate) + monthly]
1719
return base, savings
18-
20+
21+
1922
def displayRetirementWithMonthlies(monthlies, rate, terms):
2023
plt.figure('retireMonth')
2124
plt.clf()
2225
for monthly in monthlies:
2326
xvals, yvals = retire(monthly, rate, terms)
24-
plt.plot(xvals, yvals, label = 'retire:'+str(monthly))
25-
plt.legend(loc = 'upper left')
27+
plt.plot(xvals, yvals, label='retire:' + str(monthly))
28+
plt.legend(loc='upper left')
29+
30+
displayRetirementWithMonthlies([500, 600, 700, 800, 900, 1000, 1100], .05, 40 * 12)
31+
2632

27-
displayRetirementWithMonthlies([500, 600, 700, 800, 900, 1000, 1100], .05, 40* 12)
28-
2933
def displayRetirementWithRates(monthly, rates, terms):
3034
plt.figure('retireRate')
3135
plt.clf()
3236
for rate in rates:
3337
xvals, yvals = retire(monthly, rate, terms)
34-
plt.plot(xvals, yvals,
35-
label = 'retire:'+str(monthly)+ ':' + str(int(rate*100)))
36-
plt.legend(loc = 'upper left')
38+
plt.plot(xvals, yvals,
39+
label='retire:' + str(monthly) + ':' + str(int(rate * 100)))
40+
plt.legend(loc='upper left')
41+
42+
43+
displayRetirementWithRates(800, [.03, .05, .07], 40 * 12)
3744

38-
displayRetirementWithRates(800,[.03, .05, .07], 40*12)
3945

40-
4146
def displayRetirementWithMonthsAndRates(monthlies, rates, terms):
4247
plt.figure('retireBoth')
4348
plt.clf()
44-
plt.xlim(30*12, 40*12)
49+
plt.xlim(30 * 12, 40 * 12)
4550
for monthly in monthlies:
4651
for rate in rates:
4752
xvals, yvals = retire(monthly, rate, terms)
4853
plt.plot(xvals, yvals,
49-
label = 'retire:'+str(monthly)+ ':' + str(int(rate*100)))
50-
plt.legend(loc = 'upper left')
51-
52-
displayRetirementWithMonthsAndRates([500, 700, 900, 1100],
53-
[.03, .05, .07], 40*12)
54-
55-
#def displayRetirementWithMonthsAndRates(monthlies, rates, terms):
54+
label='retire:' + str(monthly) + ':' + str(int(rate * 100)))
55+
plt.legend(loc='upper left')
56+
57+
58+
displayRetirementWithMonthsAndRates([500, 700, 900, 1100],
59+
[.03, .05, .07], 40 * 12)
60+
plt.show()
61+
62+
# def displayRetirementWithMonthsAndRates(monthlies, rates, terms):
5663
# plt.figure('retireBoth')
5764
# plt.clf()
5865
# plt.xlim(30*12, 40*12)
@@ -69,9 +76,6 @@ def displayRetirementWithMonthsAndRates(monthlies, rates, terms):
6976
# label = 'retire:'+str(monthly)+ ':' + str(int(rate*100)))
7077
# plt.legend(loc = 'upper left')
7178
#
72-
#displayRetirementWithMonthsAndRates([500, 700, 900, 1100],
79+
# displayRetirementWithMonthsAndRates([500, 700, 900, 1100],
7380
# [.03, .05, .07], 40*12)
74-
#
75-
76-
77-
81+
#

0 commit comments

Comments
 (0)