In: Computer Science
In this exercise, you will test and debug a Future Value Program. |
|||||||||||||||||||||||||||||||||
The pseudocode of the program is as follows: Display user message WHILE user wants to continue get monthly investment, yearly interest rate, and years convert yearly interest rate to monthly interest rate convert years to months set the future value to zero FOR each month add monthly investment amount to future value calculate interest for month add interest to future value display future value ask if user wants to continue Display end message |
|||||||||||||||||||||||||||||||||
Test Plan
. |
|||||||||||||||||||||||||||||||||
Requirements:
|
|||||||||||||||||||||||||||||||||
(The source code in the lp_wk08_future_value.py) #!/usr/bin/env python3 choice = "y" while choice == "y": # get monthly investment monthly_investment = float(input(f"Enter monthly investment (0-1000):\t")) if not(monthly_investment > 0 and monthly_investment <= 100): print(f"Entry must be greater than 0 and less than or equal to 1000. " "Please start over.")) continue # get yearly interest rate yearly_interest_rate = float(input(f"Enter yearly interest rate (0-15):\t")) if not(yearly_interest_rate > 0 and yearly_interest_rate <= 15): print(f"Entry must be greater than 0 and less than or equal to 15. " "Please start over.") continue # get years years = int(input(f"Enter number of years (0-50):\t\t")) if not years > 0 or not years <= 15: print(f"Entry must be greater than 0 and less than or equal to 15. " "Please start over.") continue # convert yearly values to monthly values monthly_interest_rate = yearly_interest_rate / 12 months = years * 12 # calculate future value future_value = 0.0 for i in range(1, months): future_value = monthly_investment monthly_interest = future_value * monthly_interest_rate future_value += monthly_interest # display future value print() print("Future value:\t\t\t" + str(round(future_value, 2))) print() # see if the user wants to continue choice = input("Continue? (y/n): ") print() print("Bye!") |
choice = "y"
while choice in ["y","Y"] :#error for capital Y
# get monthly investment
monthly_investment = float(input("Enter monthly investment (0-1000):\t"))#error 1
if not(monthly_investment > 0 and monthly_investment <= 100):
print("Entry must be greater than 0 and less than or equal to 1000. "#error 2
"Please start over.")#error 3
continue
# get yearly interest rate
yearly_interest_rate = float(input("Enter yearly interest rate (0-15):\t")) #error 4
if not(yearly_interest_rate > 0 and yearly_interest_rate <= 15):
print("Entry must be greater than 0 and less than or equal to 15. ","Please start over.")#error 5
continue
# get years
years = int(input("Enter number of years (0-50):\t\t"))#error 6
if not years > 0 or not years <= 15:
print("Entry must be greater than 0 and less than or equal to 15. ","Please start over.")#error 7
continue
# convert yearly values to monthly values
monthly_interest_rate = yearly_interest_rate / 12
months = years * 12
# calculate future value
future_value=0.0
for i in range(months):
future_value+=monthly_investment
monthly_interest = future_value * monthly_interest_rate/100 # error 8
future_value += monthly_interest
# display future value
print()
print("Future value:\t\t\t" + str(round(future_value, 2)))
print()
# see if the user wants to continue
choice = input("Continue? (y/n): ")
print()
print("Bye!")
In have fixed all the errors and commneted error where it was
before and fixed it.
You may compare both the programs, new one and old one.
All the test cases have been checked multiple times and made
sure evrything is working fine as provided in test plan.
I hope it helps.