3. (20 points) In class, we discussed an example of how tocompute the growth of money overtime, with regular annual contributions. Let’s approach thisproblem from another angle: givenyour current financial situation and a retirement goal you have inmind, how much should youcontribute each year to achieve that goal? To make this morerealistic than our in-class example,we’ll also allow the contribution each year to grow over time.People can often contribute moreas they advance in their career and their earnings increase.Write a program named retirement calculator.py that starts bygetting the following userinputs:• Current age• Target retirement age• Current retirement savings, in USD• Target savings at retirement, in USD• Annual growth rate, as a percentage (“growth” is just a moregeneral term for the “interest”idea that we covered in class)• Amount to increase the annual contribution by each year, as apercentage. We’ll assumethat this percentage is consistent throughout the person’s entirecareer. For example, afigure of 2% might mean that the person contributes $1000 the firstyear, $1020 (2% morethan $1000) the second year, $1040.40 (2% more than $1020) thethird year, and so on.Include input validation (using a loop) on all of these to ensurethat the values must be non-negative (i.e., 0 or greater). Furthermore, include inputvalidation on the target retirement ageto ensure that it cannot be less than the user’s current age, andthe target retirement savingsto ensure that it cannot be less than the user’s currentsavings.Based on those inputs, the program should compute the minimumpossible contribution theuser can make their first year to meet their goals. Also show atable with the projected growthPage 3 of 7
COMP 1900 - Summer 2022 Lab 5 Due Wed., July 13, by 2359CDTfrom the user’s current age until retirement, formatted like theexamples below. Monetaryamounts should be rounded to two decimal places.Hints:• Start by assuming the user contributes $0 their first year. Thiswill make every other year’scontribution $0 too, since any percentage of 0 is still 0. But theuser might already haveenough saved up to meet their goals without contributing anythingextra, so this scenarioshould be considered.• If the user can’t meet their goals with $0 contributions,increase the first-year contributionto $0.01, run the simulation again, and see if they end up withenough at retirement. Ifnot, increase the first-year contribution to $0.02, and so on. Keeprepeating this processuntil you find that the ending balance meets or exceeds the user’sgoal.• This program should involve at least one nested loop! Dependingon the inputs, theprogram may take a considerable amount of time to find thesolution.Example program run (underlined parts indicate what the userenters)Your current age: -9Age must be non-negative, try again: 25Target retirement age: 20Retirement age must be at least 25, try again: 40Current savings (in USD): 400000Target savings at retirement (in USD): 0Amount must be at least $400000.00, try again: 750000Annual growth rate (in percent): 6.5Amount to increase annual contribution by each year (in percent):2Save $0.00 this year and increase it by 2.0% each year untilretirement.Projected growth:-----------------Age Year Start Growth Contribution Year End25 $ 400000.00 $ 26000.00 $ 0.00 $ 426000.0026 $ 426000.00 $ 27690.00 $ 0.00 $ 453690.0027 $ 453690.00 $ 29489.85 $ 0.00 $ 483179.8528 $ 483179.85 $ 31406.69 $ 0.00 $ 514586.5429 $ 514586.54 $ 33448.13 $ 0.00 $ 548034.6730 $ 548034.67 $ 35622.25 $ 0.00 $ 583656.9231 $ 583656.92 $ 37937.70 $ 0.00 $ 621594.6232 $ 621594.62 $ 40403.65 $ 0.00 $ 661998.2733 $ 661998.27 $ 43029.89 $ 0.00 $ 705028.1634 $ 705028.16 $ 45826.83 $ 0.00 $ 750854.9935 $ 750854.99 $ 48805.57 $ 0.00 $ 799660.56Page 4 of 7
COMP 1900 - Summer 2022 Lab 5 Due Wed., July 13, by 2359CDT36 $ 799660.56 $ 51977.94 $ 0.00 $ 851638.5037 $ 851638.50 $ 55356.50 $ 0.00 $ 906995.0038 $ 906995.00 $ 58954.67 $ 0.00 $ 965949.6739 $ 965949.67 $ 62786.73 $ 0.00 $ 1028736.4040 $ 1028736.40 $ 66867.87 $ 0.00 $ 1095604.27Example program run (underlined parts indicate what the userenters)Your current age: 25Target retirement age: 60Current balance (in USD): 0Target balance at retirement (in USD): 1500000Annual growth rate (in percent): 7Amount to increase annual contribution by each year (in percent):2Save $7992.29 this year and increase it by 2.0% each year untilretirement.Projected growth:-----------------Age Year Start Growth Contribution Year End25 $ 0.00 $ 0.00 $ 7992.29 $ 7992.2926 $ 7992.29 $ 559.46 $ 8152.14 $ 16703.8927 $ 16703.89 $ 1169.27 $ 8315.18 $ 26188.3428 $ 26188.34 $ 1833.18 $ 8481.48 $ 36503.0029 $ 36503.00 $ 2555.21 $ 8651.11 $ 47709.3230 $ 47709.32 $ 3339.65 $ 8824.13 $ 59873.1131 $ 59873.11 $ 4191.12 $ 9000.62 $ 73064.8532 $ 73064.85 $ 5114.54 $ 9180.63 $ 87360.0133 $ 87360.01 $ 6115.20 $ 9364.24 $ 102839.4634 $ 102839.46 $ 7198.76 $ 9551.53 $ 119589.7435 $ 119589.74 $ 8371.28 $ 9742.56 $ 137703.5836 $ 137703.58 $ 9639.25 $ 9937.41 $ 157280.2437 $ 157280.24 $ 11009.62 $ 10136.16 $ 178426.0238 $ 178426.02 $ 12489.82 $ 10338.88 $ 201254.7239 $ 201254.72 $ 14087.83 $ 10545.66 $ 225888.2040 $ 225888.20 $ 15812.17 $ 10756.57 $ 252456.9541 $ 252456.95 $ 17671.99 $ 10971.70 $ 281100.6342 $ 281100.63 $ 19677.04 $ 11191.14 $ 311968.8143 $ 311968.81 $ 21837.82 $ 11414.96 $ 345221.5944 $ 345221.59 $ 24165.51 $ 11643.26 $ 381030.3645 $ 381030.36 $ 26672.13 $ 11876.12 $ 419578.6146 $ 419578.61 $ 29370.50 $ 12113.64 $ 461062.7547 $ 461062.75 $ 32274.39 $ 12355.92 $ 505693.06Page 5 of 7
COMP 1900 - Summer 2022 Lab 5 Due Wed., July 13, by 2359CDT48 $ 505693.06 $ 35398.51 $ 12603.04 $ 553694.6149 $ 553694.61 $ 38758.62 $ 12855.10 $ 605308.3350 $ 605308.33 $ 42371.58 $ 13112.20 $ 660792.1251 $ 660792.12 $ 46255.45 $ 13374.44 $ 720422.0152 $ 720422.01 $ 50429.54 $ 13641.93 $ 784493.4853 $ 784493.48 $ 54914.54 $ 13914.77 $ 853322.7954 $ 853322.79 $ 59732.60 $ 14193.07 $ 927248.4655 $ 927248.46 $ 64907.39 $ 14476.93 $ 1006632.7756 $ 1006632.77 $ 70464.29 $ 14766.47 $ 1091863.5357 $ 1091863.53 $ 76430.45 $ 15061.79 $ 1183355.7858 $ 1183355.78 $ 82834.90 $ 15363.03 $ 1281553.7159 $ 1281553.71 $ 89708.76 $ 15670.29 $ 1386932.7660 $ 1386932.76 $ 97085.29 $ 15983.70 $ 1500001.75
3. (20 points) In class, we discussed an example of how to compute the growth of money over time, with regular annual co
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
3. (20 points) In class, we discussed an example of how to compute the growth of money over time, with regular annual co
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!