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

##IF YOU ARE SATISFIED WITH THE CODE, KINDLY LEAVE A LIKE, ELSE IF YOU HAVE DOUBTS KINDLY COMMENT.

# I HAVE COMMENTED OUT BY THE SIDE OF THE CODE WHERE THERE IS ERROR

CODE:

choice = "y"
while choice == "y" or choice == "Y": #error here choice can be == "Y" as well
# get monthly investment
monthly_investment = float(input(f"Enter monthly investment (0-1000):\t"))
if not(monthly_investment > 0 and monthly_investment <= 1000): #here is an error!
print(f"Entry must be greater than 0 and less than or equal to 1000. "
"Please start over.") #here is an error!
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 <= 50: #error here! 15 will be 50
print(f"Entry must be greater than 0 and less than or equal to 50. " #error here! 15 is 50 here
+"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+1): #error here! change to month+1
future_value += monthly_investment #error here! should be future_value = future_value + monthly_investment
monthly_interest = future_value * monthly_interest_rate/100 #error here! interest is always divided by 100
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!")

CODE PREVIEW:

CODE OUTPUT:


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          ...
NEED TO DEBUG // This pseudocode should create a report that contains an // apartment complex...
NEED TO DEBUG // This pseudocode should create a report that contains an // apartment complex rental agent's commission. The // program accepts the ID number and name of the agent who // rented the apartment, and the number of bedrooms in the // apartment. The commission is $100 for renting a three-bedroom // apartment, $75 for renting a two-bedroom apartment, $55 for // renting a one-bedroom apartment, and $30 for renting a studio // (zero-bedroom) apartment. Output is the...
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.
NEED TO DEBUG // This pseudocode should create a list that describes annual profit // statistics...
NEED TO DEBUG // This pseudocode should create a list that describes annual profit // statistics for a retail store. Input records contain a department // name (for example, “Cosmetics”) and profits for each quarter for // the last two years. The program should determine whether // the profit is higher, lower, or the same // for this full year compared to the last full year. start Declarations string department num salesQuarter1ThisYear num salesQuarter2ThisYear num salesQuarter3ThisYear num salesQuarter3ThisYear num salesQuarter1LastYear...
I NEED TO DEBUG THIS PSUEDOCODE // This pseudocode should determine and output the rental fees...
I NEED TO DEBUG THIS PSUEDOCODE // This pseudocode should determine and output the rental fees for cars. // Standard cars rent for $65 per day, compacts rent for $40 per day, // and subcompacts rent for $30 per day. Rentals for at least 7 days // receive a 20% discount. An error message is displayed if the car type // is not valid. start Declarations string carType num days num STD_RATE = 65 num COM_RATE = 40 num SUB_RATE...
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....
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT