Question

-----------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 and interest rate.

Here is one important goal of this assignment: You must use ("call") the 'calc_months' 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. If your function gave correct results in Assignment #4, do not change it for this assignment. Instead, just write code that calls the calc_months function and show the value returned in the table.

Specification:

  • Get just one input value from the user: the amount to be spent each month. Make sure that the user has entered a number greater than or equal to $500.
  • Produce a table that shows the number of months savings will last in 40 different situations:
    • 10 different starting balances should be used: 450000, 500000, ... , 900000.
    • For each starting balance, vary the interest rate from 3% to 9% 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 monthly spending of $5,000 (program output in blue, user input in black -- just the number 5000):

Welcome to the retirement planning tool! Enter monthly spending (at least $500): $5000 Retirement Savings Table: Starting Bal

Development Tips:

  1. To get full credit, you must use nested loops to create the table.
    • The header of the table is created as part of the initialization for the outer loop.
    • Each row that follows 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.
  2. To get full credit, the program must call the function written in Assignment #4.
  3. This Multiplication Table Sample Program is a valuable reference for this assignment.
  4. Don't forget to include comments showing documented test cases at the end of your program.

Assignment#4

def calc_months(initial_bal, interest, monthly_cost):
months = 0

while initial_bal > 0 and months < 600:
months += 1
initial_bal -= monthly_cost
initial_bal += initial_bal * (interest / 1200)
  
return months

def main():
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'))

main()

0 0
Add a comment Improve this question Transcribed image text
Answer #1

"""Already given function for calculation of the number of months savings will last.
Takes initial balance in account, interest and the monthly cost as input for calculation"""
def calc_months(initial_bal, interest, monthly_cost):
months = 0
while initial_bal > 0 and months < 600:
months += 1
initial_bal -= monthly_cost
initial_bal += initial_bal * (interest / 1200)
return months
#main function
def main():
#list of all the given starting balance of account which will be used in the table
start_bal=[450000,500000,550000,600000,650000,700000,750000
,800000,850000,900000]
#list of all the interest which will be used one by one for each starting balance
interest=[3,5,7,9]
#Starting message
print("Welcome to the retirement planning tool!")
#taking monthly spending as input
spend=int(input("Enter monthly spending(at least $500): $"))
"""if spending is less then $500 then it will keep running the loop until
a number greater than 500$ is entereed by user as mentioned in the question"""
while(spend< 500):
spend=int(input("Please enter at least $500): $"))
#printing the initial header and adjusting all the content as described in the example of table given
#Here I am not using any module for printing table instead I am providing -,space and tabs by myself
#Initialization for outer loop
print("Starting | Assumed Interest Rate \nBalance | 3% 5% 7% 9%")
print("-----------+-----------------------")
#Outer loop which will iterate over list of starting balances one by one
for bal in start_bal:
#Initialization for Inner loop which will print first cell of each row containing starting balance
print("${} |".format(bal),end='')
#Inner loop which will iterate over all interest one by one for each strting balance
for i in interest:
#printing space to adjust content in table
print(" ",end='')
#calling the given calc_months function by passing spend, bal, i to it
#Function will return the number of months saving will last
print(calc_months(bal,i,spend),end='')
#printing space to adjust content in table
print(" ",end='')
#Printing new line so that next calculation for different starting balance will start from next row
print()
  
#Calling main function
main()
  
te calc.py - C:/Users/Megha/AppData/Local/Programs/Python/Python37-32/calc.py (3.7.4) File Edit Format Run Options Window Helfor i in interest: #printing space to adjust content in table print( , end=) #calling the given calc months function by pThe LUIL Tel Deuuy UPLIUIS VILTUUW TICIP Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 32 bit (Inte

Add a comment
Know the answer?
Add Answer to:
-----------Python program------------------- Instructions: For this assignment, you will write complete a program that allows a customer...
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
  • 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...

  • PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do...

    PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do one of five things at a time: 1. Add students to database. • There should be no duplicate students. If student already exists, do not add the data again; print a message informing student already exists in database. • Enter name, age, and address. 2. Search for students in the database by name. • User enters student name to search • Show student name,...

  • Write them in python IDLE ***** 5. Average Rainfall Write a program that uses nested loops...

    Write them in python IDLE ***** 5. Average Rainfall Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations,...

  • need help with python program The objectives of this lab assignment are as follows: . Input...

    need help with python program The objectives of this lab assignment are as follows: . Input data from user Perform several different calculations Implement conditional logic in loop • Implement logic in functions Output information to user Skills Required To properly complete this assignment, you will need to apply the following skills: . Read string input from the console and convert input to required numeric data-types Understand how to use the Python Modulo Operator Understand the if / elif /...

  • using this code to complete. it python 3.#Display Program Purpose print("The program will show how much...

    using this code to complete. it python 3.#Display Program Purpose print("The program will show how much money you will make working a job that gives a inputted percentage increase each year") #Declaration and Initialization of Variables userName = "" #Variable to hold user's name currentYear = 0 #Variable to hold current year input birthYear = 0 #Variable to hold birth year input startingSalary = 0 #Variable to hold starting salary input retirementAge = 0 #Variable to hold retirement age input...

  • Assignment: Write a program in C++ that allows a customer to go on-line shopping. This is...

    Assignment: Write a program in C++ that allows a customer to go on-line shopping. This is a start-up venture and the stock of our on-line company is currently limited to the following items: A gift card to Home Depot, $50.00 A bottle of cologne (The One by Dolce Gabbana), $24.00 3. Akeychainwithabathtubornament,$14.00 4. Acard,$4.00 Although all items are in stock, the customer should only be made aware of the items that he or she can afford. In addition, demand for...

  • In this assignment you are asked to write a python program to maintain the Student enrollment...

    In this assignment you are asked to write a python program to maintain the Student enrollment in to a class and points scored by him in a class. You need to do it by using a List of Tuples What you need to do? 1. You need to repeatedly display this menu to the user 1. Enroll into Class 2. Drop from Class 3. Calculate average of grades for a course 4. View all Students 5. Exit 2. Ask the...

  • Help please, write code in c++. The assignment is about making a hangman game. Instructions: This...

    Help please, write code in c++. The assignment is about making a hangman game. Instructions: This program is part 1 of a larger program. Eventually, it will be a complete Hangman game. For this part, the program will Prompt the user for a game number, Read a specific word from a file, Loop through and display each stage of the hangman character I recommend using a counter while loop and letting the counter be the number of wrong guesses. This...

  • assignment 1 Make sure you are able to write a python program as described in the...

    assignment 1 Make sure you are able to write a python program as described in the text. You will be working in repl.it Title your program temperature. Add a comment to say that this program converts Fahrenheit to Centigrade. Create variables: fahrenheit and centigrade values my name Have the program prompt the user (the instructor) for a value for the fahrenheit variable. Convert the value to centigrade, using this formula: (fahrenheit - 32) * ÷ 9 = centigrade Have the...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

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