Question

In: Computer Science

In this exercise, you will test and debug a Future Value Program. The pseudocode of the...

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

Case

Input

Expected

User entry for monthly_investment

Not a number

Error, program stops

User entry for yearly interest rate

Not a number

Error, program stops

User entry for number of years

Not a number

Error, program stops

User entry for monthly_investment

Not >0 and <=1000

Display a message accordingly, ask user to start over

User entry for yearly interest rate

Not >0 and <=15

Display a message accordingly, ask user to start over

User entry for number of years

Not >0 and <=50

Display a message accordingly, ask user to start over

User entry for a new calculation

Anything other than “y” or “Y”

Display “Bye!”

User entry for a new calculation

‘y’

Start over

User entry for a new calculation

‘Y’

Start over

User entries are all valid

Enter 100 for Monthly investment, 12 for yearly_interest_rate, and 1 for years

Display future value which should be 1280.93.

.

Requirements:

  1. Open the lp_w08_future_value.py file and review the code. lp_wk08_future_value.py  
  2. Thoroughly test the program. You may use the test plan as a guide, then note any inaccurate results that you discover during testing.
  3. Debug and fix errors. (Hint: total 5 errors). Each fixed error is worth 8 points.
  4. Test the program with the same data to be sure it works correctly.
  5. Add an in-line comment on each line where you found the errors.
  6. Upload your correct program with comments. Please simply upload the .py file, and do not upload a zipped file

(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!")

Solutions

Expert Solution

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.


Related Solutions

In this exercise, you will test and debug a Future Value Program. The pseudocode of the...
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          ...
4. Write a program trace for the pseudocode in Exercise • E4.6, assuming the input values...
4. Write a program trace for the pseudocode in Exercise • E4.6, assuming the input values are 4 7 –2 –5 0. Ans. first value minimum output • E4.6 --> This is the pseudocode Set a Boolean variable "first" to true. While another value has been read successfully If first is true Set the minimum to the value. Set first to false. Else if the value is less than the minimum Set the minimum to the value. Print the minimum.
Write and submit a test driver program employeeTest.java, the pseudocode is below. start instantiate a Employee...
Write and submit a test driver program employeeTest.java, the pseudocode is below. start instantiate a Employee object get input from user for worker name loop while user does not enter "" Set workers name get input from user for employeeId set workers employeeId get input from user for shift (day/night) set workers shift (input "day" = true , input "night" = false) get input from user workers hourly pay set workers hourly pay get input from user total hours worked...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the HTML file that references the JavaScript file. Use prompt to collect names of persons from the user. When the user enters ‘DONE’, your script should stop collecting more names. Then, it should ask the user to specify the following style properties: Border size? 2px, 5px, or 8px. Border Color? blue, red, green, and black. Border style? solid, dotted, dashed, and double. The HTML document...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the HTML file that references the JavaScript file. Use prompt to collect names of persons from the user. When the user enters ‘DONE’, your script should stop collecting more names. Then, it should ask the user to specify the following style properties: - Border size? 2px, 5px, or 8px. - Border Color? blue, red, green, and black. - Border style? solid, dotted, dashed, and double....
For this assignment you will develop pseudocode and write a C++ program for a simple calculator....
For this assignment you will develop pseudocode and write a C++ program for a simple calculator. You will create both files in Codio. Put your pseudocode and C++ code in the files below. PSEUDOCODE FILE NAME: Calculator.txt C++ SOURCE CODE FILE NAME : Calculator.cpp DESCRIPTION: Write a menu-driven program to perform arithmetic operations and computations on a list of integer input values. Present the user with the following menu. The user will choose a menu option. The program will prompt...
Exercise A3-20 (Algorithmic) Future Values of an Annuity Use Future Value Tables or your calculator to...
Exercise A3-20 (Algorithmic) Future Values of an Annuity Use Future Value Tables or your calculator to complete the requirements below. On December 31, 2020, you sign a contract to make annual deposits of $5,200 in an investment account that earns 10%. The first deposit is made on December 31, 2020. Required: 1. Calculate what the balance in this investment account will be just after the seventh deposit has been made if interest is compounded annually. Round your answer to the...
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
In Python Find the errors, debug the program, and then execute to show the output. def...
In Python Find the errors, debug the program, and then execute to show the output. def main():     Calories1 = input( "How many calories are in the first food?")     Calories2 = input( "How many calories are in the first food?")     showCalories(calories1, calories2)    def showCalories():     print('The total calories you ate today', format(calories1 + calories2,'.2f'))
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT