View the step-by-step solution to:

a Assignment 4 -- Retirement Planning, Part 1 Instructions: write the first part of a program that allows a customer to plan for retirement . Note:


a

Assignment 4 -- Retirement Planning, Part 1

Instructions:

 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_final_balance' that calculates the final balance in a retirement account after annual savings accrue for and earn interest for a number of years. This is a simulation problem similar to the Credit Card sample program, except it is to be written as a function definition (which means, among other things, that it uses parameters instead of user input). Here is the specification:

  • The function requires3 parameters: thestarting agefor saving, theamount saved each year, and thepercentage interest rate. This function may assume that the values have been previously validated -- no input validation is needed in this function.
  • Saving is assumed tostop at age 70.
  • The functionuses a loopto perform asimulationof retirement savings. The loop iterates one time for each year that savings occur. Each year, the account balance is increased by the amount saved each year, and then -- after this increase -- the account earns one year's interest.
  • The function shouldreturn the final balanceat age 70.

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


print('$' + format(calc_final_balance( 30, 3000, 6 ), '.2f'))

print('$' + format(calc_final_balance( 20, 2000, 5.5 ), '.2f'))


should write on the web page the results $492143.05 and $519518.88. Choose test cases that check the function thoroughly, and document your testing in comments.

Here is a simple test case you can more easily trace by hand: calc_final_balance( 65, 2000, 10 ) should return the value 13431.22.

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 headerto 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.
  • Includeblank lineswhere appropriate to make the program easier to read.
  • Use descriptivevariable names.
  • Include comments at the end of your program that describe at least 3 test cases and the results.


Completed Assignment 4 and this is the coding for Assignment 4 Part 1

def calc_final_balance(age, saved, percentage):

time_left = 70 - age # get the number of years left

balance = 0

percentage = float(

percentage) / 100 # percentage division

percentage += 1

for _ in range(time_left): # loop to go through each year

balance += saved

balance *= percentage # get the interest, and multiply it to percentage

return balance # return the amount

print (calc_final_balance( 65, 2000, 10 ))

print('$' + format(calc_final_balance( 30, 3000, 6 ), '.2f'))

print('$' + format(calc_final_balance( 20, 2000, 5.5 ), '.2f'))







Assignment 5 -- Retirement Planning, Part 2

Instructions: For this assignment, you will write complete a program that allows a customer to plan for retirement.

Part 2: Generate a Retirement Planning Table:

It's hard to decide how much you need to save for retirement. To help your customer visualize how much she needs to save for retirement, write a program that allows the user to generate a retirement planning table for a specified annual savings amount showing the final account balance upon retirement for various combinations of starting age for saving and interest rate.

Here is one important goal of this assignment: You must use ("call") the 'calc_final_balance' function you wrote for Assignment #4 in this assignment. This means that you need to put a copy of that function definition at the beginning of your code for this assignment.

Specification:

  • Get just one input value from the user: the amount to be saved each year. Make sure that the user has entered a number greater than or equal to $100 (i.e. input validation is required).
  • Produce a table that shows the final account balance in 40 different situations:
  • 10 different starting ages should be used: 20, 25, 30, ... , 65.
  • For each starting age, vary the interest rate from 4% to 10% in steps of 2%.
  • Your program must use nested loops to produce the table.
  • Here is what the table would look like if the user specifies an annual savings of $3,000 (program output in blue, user input in black -- just the number 3000):


Development Tips:

  1. To get full credit, you must use nested loops to create the table.
  • The first row of the table is created as part of the initialization for the outer loop.
  • Each row after the first is created by one pass through the outer loop.
  • In each row, the first cell is created as part of the initialization for the inner loop. The remaining cells are created by the body of the inner loop.
  1. To get full credit, the program must call the function written in Assignment #4.
  2. This Multiplication Table Sample Program is a valuable reference for this assignment.
  3. Don't forget to include comments showing documented test cases at the end of your program.

Documentation & Style Specifications -- refer to Assignment #4

Grading

/14 correct output and correct solution including using nested loops and calling 'calc_final_balance'

/3 documented test cases 

/3 proper comments; good variable names; declarations; indenting; blank lines

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question