Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 4 -- Retirement Planning, Part 1 Instructions: For this assignment, you will write the first part of a program that allows a customer to

Assignment 4 -- Retirement Planning, Part 1

Instructions:

For this assignment, you will write the first part of a program that allows a customer to plan for retirement. Note: This program has no user input

Write a "pure" Python function named 'calc_months' that calculates the number of months an initial retirement account balance will last as it is spent down during retirement. This is a simulation problem similar to the Credit Card sample program, except it is to be written as a function (which means, among other things, that it uses parameters instead of user input). Here is the specification:

  • The function requires 3 parameters: the initial balance in the account at retirement, the annual percentage interest rate, and the amount spent each month. This function may assume that the values have been previously validated -- no input validation is needed in this function.
  • The function uses a loop to perform a simulation of the process of spending retirement savings. The loop iterates one time for each month. Each month, the account balance is reduced by the amount spent, and then -- after this -- the account earns one month's interest. (Hint: be careful how interest is calculated!)
  • The function uses a loop to perform a simulation of retirement savings. The simulation loop should continue executing as long as the account balance is greater than zero AND the number of months is less than 600. This second condition is required because it is possible that the balance will grow rather than shrink if the monthly withdrawals are too low -- and that could result in an infinite loop!
  • The function should return the number of months it takes for the account balance to drop to zero or less (or 600 if the simulation stopped at that point). Notice that the function should return a single number.

TEST the 'calc_months' function by adding statements in the 'main program' to print out the results for several test cases and confirm that it is correct. For example, these statements:

print(calc_months( 300000, 6, 3000 )) print(calc_months( 10000, 0, 2000 )) print(calc_months( 1000000, 4.5, 4200 )) print(format(calc_months( 1000000, 4.6, 4200 ), '.2f'))

should write in the shell window the results 138, 5, 589 and 600.00. Choose test cases that check the function thoroughly (hint: what happens if the monthly spending is very high or very low?), and document your testing in comments.

Documentation & Style Specifications

  • Include a main comment block at the beginning of the file listing that has your name, date, class and section number, and a brief description (one or two lines) of the project.
  • Include a comment block before the function header to describe a) what the function does and b) how the function's parameters are used. Follow the style you see in the posted examples, and in particular the cube_root.py sample program, which demonstrates the difference between the comment block at the very beginning of a code file and the comment block located before a function header.
  • Include blank lines where appropriate to make the program easier to read.
  • Use descriptive variable names.
  • Include at least 3 documented test cases -- comments at the end of your program that describe at least 3 tests you performed, and the results you saw, and why you believe the results are correct.

Grading

/10 function definition including simulation loop /5 documented test cases /5 proper comments; good variable names; indenting; blank lines

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

Students also viewed these Databases questions

Question

=+6 Who is the peer of the IA ?

Answered: 1 week ago

Question

=+herself to in terms of equity with regard to this assignment?

Answered: 1 week ago