-
Notifications
You must be signed in to change notification settings - Fork 0
/
DonGass_hw5_task2.py
60 lines (43 loc) · 1.74 KB
/
DonGass_hw5_task2.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
# -*- coding: utf-8 -*-
"""
Compare a lump sum payment option vs an annuitized payment option
Created on Wed Sep 20 19:54:38 2017
@author: Don Gass
"""
#
import locale
locale.setlocale(locale.LC_ALL, '')
from prettytable import PrettyTable
restable = PrettyTable()
restable.field_names = ['Number of Payments', 'Calculated Value']
restable.align['Number of Payments'] = 'c'
restable.align['Calculated Value'] = 'r'
#get user input
print('Which is better - a lump sum payment or n annuitized payments?\n')
lumpsum = int(input('Enter amount of lump sum payment (as an integer): '))
annuityamount = int(input('Enter yearly payment amount (as an integer): '))
annuitytime = int(input('How many years will you recieve yearly payments?: '))
rate = int(input('Enter rate % (positive real number): '))
#setup additional variables to be used in calculations
annual_rate = rate / 100
compound = 1
#lump sum calculation
lumpfinalamount = lumpsum*((1 + annual_rate/compound)**(compound*annuitytime))
#annuitized payment calculation
numpayments = 1
currentamount = 0
while numpayments <= annuitytime:
currentamount = currentamount + annuityamount
currentamount = currentamount * 1.05
restable.add_row([numpayments, locale.currency(currentamount, grouping=True)])
numpayments += 1
#print results
print('\n\n\nAfter', annuitytime, 'years at', rate,'% interest:\n')
print('Lump sum of', lumpsum, 'will return: ', end='')
print(locale.currency(lumpfinalamount, grouping=True),'\n')
print(str(annuitytime), 'years of $' + str(annuityamount), 'payments results:\n')
print(restable)
if currentamount > lumpfinalamount:
print('Annuity options is better.')
else:
print('Lump sum option is better.')