Question

Instructions: For this assignment, you will write the first part of a program that allows a...

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_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 requires 3 parameters: the starting age for saving, the amount saved each year, and the percentage interest rate. This function may assume that the values have been previously validated -- no input validation is needed in this function.
  • Saving is assumed to stop at age 70.
  • The function uses a loop to perform a simulation of 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 should return the final balance at 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 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 comments at the end of your program that describe at least 3 test cases, the results you saw, and why you believe those results are correct, as you did for previous assignments.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

'''function to calculate total savings for given period'''
def calc_final_balance(strart_age,savings_each,percentage_int):
#variable to store total savings
sum_of_money = 0
#loop from start age to 70
for i in range(strart_age,71):
#for last year dont add or calculate interest because it stops at 70
if i==70:
#pass does nothing
pass
  
else:
#add savings each year then add interest tot it
sum_of_money = sum_of_money + savings_each
sum_of_money = sum_of_money*(1+(percentage_int/100))

return sum_of_money
print('$' + format(calc_final_balance( 30, 3000, 6 ), '.2f'))
print('$' + format(calc_final_balance( 20, 2000, 5.5 ), '.2f'))
print('$' + format(calc_final_balance( 65,2000,10 ), '.2f'))

output:

explanation:

first we take sum_of_money as 0.

in for loop we loop through start age to 70.

if condition:

when someone enters age 70, for that year we dont need to add savings and interest because it stops at 70.

else:

add the savings to each year and add interest also.

return and display the total savings.

Note: if u have any doubt, let me know.

Add a comment
Know the answer?
Add Answer to:
Instructions: For this assignment, you will write the first part of a program that allows a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • -----------Python program------------------- Instructions: For this assignment, you will write complete a program that allows a customer...

    -----------Python program------------------- 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 long her nest egg will last, write a program that allows the user to generate a retirement planning table showing the number of months the savings will last for various combinations of starting account balance...

  • Write a C++ program that calculates the discount of the original price of an item and...

    Write a C++ program that calculates the discount of the original price of an item and displays the new price, and the total amount of savings. This program should have a separate header (discount.h), implementation (discount.cpp) and application files (main.cpp). The program must also have user input: the user must be prompted to enter data (the original price, and the percent off as a percentage). There must also be a validation, for example: Output: “Enter the original price of the...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • Write in C++ using emacs. Write a program that calculates the ending balance of several savings...

    Write in C++ using emacs. Write a program that calculates the ending balance of several savings accounts. The program reads information about different customers’ accounts from an input file, “accounts.txt”. Each row in the file contains account information for one customer. This includes: the account number, account type (premium, choice, or basic account), starting balance, total amount deposited, and total amount withdrawn. Your program should: - open the file and check for successful open, - then calculate the ending balance...

  • Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment...

    Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your...

  • You will write a C program, q1 sequence.c, that computes the value of the nth term...

    You will write a C program, q1 sequence.c, that computes the value of the nth term in any recursive sequence with the following structure: an = c1 · an−1 + c2 · an−2 a0 > 0 a1 > 0 c1 6= 0 c2 6= 0 Your C program will take 5 integer arguments on the command line: n, a0, a1, c1 and c2. n must be an integer greater than or equal to 0. If more or fewer arguments are...

  • 1. The first small program realizes the following functions: (1) The program allows input of ID...

    1. The first small program realizes the following functions: (1) The program allows input of ID (3-digit integer representation), month (1-12), revenue and record these information in file1 (2) If the ID entered by the user and the income of the corresponding month already exist in file1, remind: the income information has been entered, please do not repeat the entry 2. The second small program realizes the following functions: (1) Calculate the tax payable for each ID in file1 in...

  • You will create a new project. Type in the following program and run it to produce...

    You will create a new project. Type in the following program and run it to produce the output for the program. Good practice in writing a program in any language, including Python, is to add comments for each line and state clearly what is the program input and output. Your program must include comments, so a reader will know exactly what you are trying to do in each line of code and allow for easy maintenance. Beginning a line with...

  • /************************************************************************************ * Program: PRG/420 Week 5 * Purpose: Week 5 Coding Assignment * Programmer: TYPE YOUR...

    /************************************************************************************ * Program: PRG/420 Week 5 * Purpose: Week 5 Coding Assignment * Programmer: TYPE YOUR NAME HERE * Class: PRG/420 * Creation Date: TYPE TODAY'S DATE HERE ************************************************************************************* * Program Summary: * This program converts a given date to a string. * The code includes exception handling for a ParseException. ************************************************************************************/ package prg420week5_codingassignment; import java.util.*; // wildcard to import all the util. classes import java.text.*; // wildcard to import all the text classes public class PRG420Week5_CodingAssignment { public static...

  • Python assignment:  Write a program that asks for the user's age. Based on their response print "You...

    Python assignment:  Write a program that asks for the user's age. Based on their response print "You can vote" (18 years old or older) or "You can't vote" and also whether or not he/she is a senior citizen (over 64). If senior citizen print "You're a Senior Citizen...you deserve two votes"!   Use the Idle editor and don't forget the .py extension. Good luck.          Your python program will be graded on the following:     Execution of the program gives the correct...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT