Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction This problem set will introduce you to using control flow in Python and formulating a computational solution to a problem. We will design and

Introduction

This problem set will introduce you to using control flow in Python and formulating a computational solution to a problem. We will design and write three simple Python programs, test them, and hand them in. Be sure to read this problem set thoroughly.

Paying Off Credit Card Debt

Each month, a credit card statement will come with the option for you to pay a minimum amount of your charge, usually 2% of the balance due. However, the bank earns money by charging interest on the balance that you dont pay. So even if you pay credit card payments on time, interest is still accruing on the outstanding balance. Say youve made a $5,000 purchase on a credit card with 18% annual interest rate and 2% minimum monthly payment rate. After a year, how much is the remaining balance? Use the following equations.

Minimum monthly payment = Minimum monthly payment rate x Balance (Minimum monthly payment gets split into interest paid and principal paid)

Interest Paid = Annual interest rate / 12 months x Balance

Principal paid = Minimum monthly payment Interest paid

Remaining Balance = Balance Principal paid

For month 1, we can compute the minimum monthly payment by taking 2% of the balance:

Minimum monthly payment = .02 x $5000.0 = $100.0

We cant simply deduct this from the balance because there is compounding interest. Of this $100 monthly payment, compute how much will go to paying off interest and how much will go to paying off the principal. Remember that its the annual interest rate that is given, so we need to divide it by 12 to get the monthly interest rate.

Interest paid = .18/12.0 x $5000.0 = $75.0

Principal paid = $100.0 $75.0 = $25

The remaining balance at the end of the first month will be the principal paid this month subtracted from the balance at the start of the month.

Remaining balance = $5000.0 $25.0 = $4975.0

For month 2, we repeat the same steps:

Minimum monthly payment = .02 x $4975.0 = $99.50

Interest Paid = .18/12.0 x $4975.0 = $74.63

Principal Paid = $99.50 $74.63 = $24.87

Remaining Balance = $4975.0 $24.87 = $4950.13

After 12 months, the total amount paid is $1167.55, leaving an outstanding balance of $4708.10. Pretty depressing!

Paying the Minimum Problem 1

Write a program to calculate the credit card balance after one year if a person only pays the minimum monthly payment required by the bank each month. Ask for the following three information from user: 1. The outstanding balance on the credit card 2. Annual interest rate 3. Minimum monthly payment rate For each month, print the minimum monthly payment, remaining balance, principle paid. All numbers should be rounded to the nearest penny. Finally, print the result, which should include the total amount paid that year and the remaining balance.

Paying Debt Off In a Year Problem 2

Now we are going to write a program that calculates the minimum fixed monthly payment needed in order pay off a credit card balance within 12 months. We will not be dealing with a minimum monthly payment rate. Take the following floating point numbers:

1. The outstanding balance on the credit card

2. Annual interest rate as a decimal

Print out the fixed minimum monthly payment, number of months (at most 12 and possibly less than 12) it takes to pay off the debt, and the balance (likely to be a negative number).

Assume that the interest is compounded monthly according to the balance at the start of the month (before the payment for that month is made). The monthly payment must be a multiple of $10 and is the same for all months. Notice that it is possible for the balance to become negative using this payment scheme. In short:

Monthly interest rate = Annual interest rate / 12.0

Updated balance each month = Previous balance * (1 + Monthly interest rate) Minimum monthly payment

Start at $10 payments per month and calculate whether the balance will be paid off (taking into account the interest accrued each month). If $10 monthly payments are insufficient to pay off the debt within a year, increase the monthly payment by $10 and repeat.

Using Bisection Search to Make the Program Faster

Youll notice that in the problem 2, your monthly payment had to be a multiple of $10. Why did we make it that way? We can try changing the code so that the payment can be any dollar and cent amount (in other words, the monthly payment is a multiple of $0.01). Does your code still work? It should, but you may notice that your code runs more slowly, especially in cases with very large balances and interest rates. How can we make this program faster? We can use bisection search. We are searching for the smallest monthly payment such that we can pay off the debt within a year. What is a reasonable lower bound for this value? We can say $0, but you can do better than that. If there was no interest, the debt can be paid off by monthly payments of one-twelfth of the original balance, so we must pay at least this much. One-twelfth of the original balance is a good lower bound. What is a good upper bound? Imagine that instead of paying monthly, we paid off the entire balance at the end of the year. What we ultimately pay must be greater than what we wouldve paid in monthly installments, because the interest was compounded on the balance we didnt pay off each month. So a good upper bound would be one-twelfth of the balance, after having its interest compounded monthly for an entire year.

Monthly payment lower bound = Balance / 12.0

Monthly payment upper bound = (Balance * (1 + (Annual interest rate / 12.0)) ** 12.0) / 12.0

Problem 3

Write a program that uses these bounds and bisection search (for more info check out the Wikipedia page here) to find the smallest monthly payment to the cent such that we can pay off the debt within a year. Try it out with large inputs, and notice how fast it is. Produce the output in the same format as you did in the problem 2.

write a python code of these three questions pls.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

8. Providing support during instruction.

Answered: 1 week ago