Question

This program asks the user for the initial balance or principal (e.g. $1234.56), the interest rate...

This program asks the user for the initial balance or principal (e.g. $1234.56),
the interest rate (as a percentage but without the % sign), number of years, and
how frequently compounded (supports the words "daily" for 365, "weekly" for 52,
"monthly" for 12, "quarterly" for 4, and "annually" for 1.
If then displays the total accrued amount (i.e. the principal plus the interest).

The output should look exactly like money.

Make sure you create each of the functions appropriately. All input() and
print() calls are in main() [do NOT use input() or print() in any ].

The file tests.py contains the unit tests that you will write for each function.
Make sure to open that file and complete the required tests.

EXAMPLE 1:
Principal: $10000.00
Interest Rate: 3.875
Number of Years: 7.5
Frequency of Compounds (daily, weekly, monthly, quarterly, or annually): monthly
You will have accrued $13366.37
0 0
Add a comment Improve this question Transcribed image text
Answer #1

A simple formula can solve your problem. You need not have any complex functions in it. Since you did not specified to not use any formulae. I am just solving theses using the formula.

Note : Please mention programming language explicitly. Since you told "tests.py" as file name, I am assuming it as python and answering here.

Program :

#Input the principal

original_principal = int(input('Principal: '))

# Input the annual interest rate.

annual_interest = float(input('Interest Rate(%): '))
annual_interest = annual_interest / 100

# Input number of years account will earn interest.

total_years = float(input('Number of Years: '))

# Input times per year the interest is compounded.
c=0
while c==0:
compound = input("Frequency of Compounds (daily, weekly, monthly, quarterly, or annually):")
if compound=="annually":
c=1
elif compound=="monthly":
c=12
elif compound=="weekly":
c=52
elif compound=="daily":
c=365
elif compound=="quarterly":
c=4
else:
print("Please enter one of the option specified in brackets:")
# Calculate ending principle amount after earning
# interest for a specified amount of years.

ending_principal = (original_principal * (1 + annual_interest
/ c) ** (c * total_years)
)

# Display the ending principle amount.

print('At the end of ', total_years, 'years you will have $',
format(ending_principal, '.2f'))

Outputs :

Test case 1 :

Here I am checking it for daily basis. Also I have written the code in such a way that. if user enters any other string for compounded frequency, it warns and prompts again.

Test Case 2:

This was the test case provided by you.

Since the code is python , I am pasting the screen shot of the code so that you don't confuse with the indentation.

Add a comment
Know the answer?
Add Answer to:
This program asks the user for the initial balance or principal (e.g. $1234.56), the interest rate...
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
  • PROGRAMMING IN C. 1) The first program will compute compounded interest. Suppose you invest $1000.00 at...

    PROGRAMMING IN C. 1) The first program will compute compounded interest. Suppose you invest $1000.00 at an interest rate of 2% per year. If the interest is computed at the end of each day, it is added to your account (i.e., the interest is compounded daily). Print what the account value will be at the end of each year for 20 years. Use data type double for money. For 365 days per year (ignore leap year), the daily interest rate...

  • You take a 12-years fixed rate loan at 5.0 % annual interest rate with initial principal...

    You take a 12-years fixed rate loan at 5.0 % annual interest rate with initial principal of $400,000. The repayment is scheduled as quarterly instalments. (a) Solve for your quarterly payment. (6 marks) (b) Three years later, you decide the change to monthly instalment for the remaining period at the same interest rate. Solve for the monthly payment. (12 marks) (c) Calculate the total interest that you need to pay for the twelve years. (2 marks)

  • You take a 12-years fixed rate loan at 5.0% annual interest rate with initial principal of $400,000. The repayment is s...

    You take a 12-years fixed rate loan at 5.0% annual interest rate with initial principal of $400,000. The repayment is scheduled as quarterly instalments. (a) Solve for your quarterly payment. (6 marks) (b) Three years later, you decide the change to monthly instalment for the remaining period at the same interest rate. Solve for the monthly payment. (12 marks) c) Calculate the total interest that you need to pay for the twelve years. (2 marks)

  • Write a program in Python that computes the interest accrued on an account. You can modify...

    Write a program in Python that computes the interest accrued on an account. You can modify the “futval.py” program given in Chapter 2 to accomplish it. Your program should use a counted loop rather than a formula. It should prompt the user to enter the principal amount, the yearly interest rate as a decimal number, the number of compounding periods in a year, and the duration. It should display the principal value at the end of the duration. To compute...

  • You need to save a total of $7,500 in order to buy a new motorcycle. You...

    You need to save a total of $7,500 in order to buy a new motorcycle. You are starting with savings of $4,000 but will make no additional contributions. The annual interest rate is 5%. In excel compute how long you would need to wait in order to reach your goal for interest that is compounded annually, semi-annually, quarterly, monthly, weekly, and daily. Which of the following accurately depicts this calculation? FV $7,500 $7,500 $7,500 $7,500 $7,500 $7,500 PV $4,000 $4,000...

  • Styles Program Description Write a C++ program that computes and displays employees' earnings. Prompt the user...

    Styles Program Description Write a C++ program that computes and displays employees' earnings. Prompt the user for type of employee (hourly ("h"or "H") or management ("'m" or "M") If the employee is management: . get the annual salary get the pay period (weekly ("w" or "W"), bi-weekly ("b" or "B") or monthly ("m" or e compute the gross salary for the pay period (Divide annual salary by 52 for weekly, 26 for bi-weekly, and 12 for monthly) deduct from gross...

  • ents due annually, on March 1. Each payment consists of $20,000 principal plus one year's interest....

    ents due annually, on March 1. Each payment consists of $20,000 principal plus one year's interest. redit More Info 2018 Mar. 1 Borrowed $300,000 from Bartow Bank. The 15-year, 9% note requires payments due annually, on March 1. Each psyment consists of $20,000 principal plus one year's interest Dec. 1 Mortgaged the warehouse for $400,000 cash with Sammon Bank. The mortgage requires monthly payments of $6,000. The interest rate on the note is 6 % and accrues monthly. The first...

  • c++ and please add tables and everything and make sure program is complete. Write a menu...

    c++ and please add tables and everything and make sure program is complete. Write a menu driven program, which would compute compound interest and a monthly payment for a loan. The user will be given a choice to display the info on the screen or to a filo Menu will be the following Enter (1) to calculate your loan monthly payment Enter (2) to calculate your loan monthly payment & write to a file Tips: Compound Interest Formula A =...

  • Amortization Table On April 1, 2018, Clyde Barrow Company bought a delivery truck for $54,000 on...

    Amortization Table On April 1, 2018, Clyde Barrow Company bought a delivery truck for $54,000 on a 6%, five-year installment note. You have been tasked with preparing an amortization table in Excel for the bookkeeper to assist him in recording the monthly payments, with the first payment starting on May 1, 2018. Prepare a monthly amortization table for the loan showing the payment date, payment, principal part of the payment, the interest portion of the payment, and the remaining balance....

  • You wish to buy a car for $12,000 at a 5% annual interest rate, compounded monthly....

    You wish to buy a car for $12,000 at a 5% annual interest rate, compounded monthly. The loan will be repaid in 5 years with monthly payments. What is your monthly payment (calculated with the equations on the next page)? Compare your answer to that obtained with the built in function, PMT. Be sure to label all cells appropriately. (There is no need to create a monthly payment table, simply use the equations on the next page.) Loans: where: and,...

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