CSci 150: Foundations of computer science I
Home Syllabus Assignments Tests

Assignment 2: Traditional IRAs

Due: 9:00am, Monday, February 8. Value: 30 pts. Submit to Sauron. [Instructions]

The U S government provides several tax incentives to encourage middle-income individuals to invest toward their retirement.* One mechanism is called the Traditional IRA. This allows a taxpayer to create an IRA account, frequently in a mutual fund working in the stock market. Then each year, the taxpayer can invest up to $5,000 of income in the IRA account, and that invested income is then exempt from income taxes. Also, any interest or capital gains in the account are tax-exempt. Tax is not avoided completely, though: Income tax must eventually be paid when money is later removed from the account, usually during retirement. Overall, though, you come out well ahead of doing your investing outside an IRA.

Your assignment is to write a program that estimates how much money you can receive in retirement based on your IRA account if you make regular annual investments. Your program will read four inputs from the user.

Age at which you start investing
Amount invested each year
Estimated interest rate
Age at which you plan to retire

It should then display how much will be in your account after each year, followed by the amount of interest received in the year when you retire (which is roughly how much you would be able to withdraw annually thereafter). An example of a run of the program is as follows, with user input in boldface.

Starting age? 20          (Feel free to improve on this user interface.)
Annual deposit? 4000.00
Interest rate? 4.0
Retiring age? 64
20 : 4000
21 : 8160.0               (This is 4000 * 1.04 + 4000.)
22 : 12486.4              (This is 8160 * 1.04 + 4000.)
23 : 16985.856
 :                        Lines omitted. Another page has the complete output
63 : 461651.507833
64 : 484117.568146
After retirement, you can withdraw $19364.7027258 each year.
            $19,364.70 is 4% of the age-64 balance, since the interest rate is 4%.

If, however, you wait until 30 to start investing $4,500 each year, and if you assume a 4.25% return, then upon retirement at age 67 you'd be able to withdraw $17,382.80 each year.

Optional: You may want the program to display its output with exactly two places after the decimal point. To do this in Python, use the built-in format function, which converts a parameter into a string based on a format specifier given as a second parameter. In this case, you'd want something like:

print format(money, '.2f')

The parameter '.2f' indicates to format money as a floating-point number with two places after the decimal point. If money holds the value 2.71828, then format would compute the string '2.72', so on the screen would appear 2.72.


* Because of the effects of interest, many financial advisors suggest that people start early investing in the stock market toward retirement, either while in college or immediately thereafter. Two reasonable sources of financial advice are the federal government and a mainstream financial radio program.

Incidentally, the 4% interest rate is fairly realistic. From 1950 to 2008, the S&P 500 averaged a 3.76% return in real terms (i.e., after factoring inflation out).