Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

Problem Set 2 - Unit 2 - Simple Programs - Problem-1

The document describes a problem set question that requires writing a program to calculate the remaining credit card balance after one year if only paying the minimum monthly payment. It provides the variables and equations needed as well as sample test cases to check the code against.

Uploaded by

hr.promosi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Problem Set 2 - Unit 2 - Simple Programs - Problem-1

The document describes a problem set question that requires writing a program to calculate the remaining credit card balance after one year if only paying the minimum monthly payment. It provides the variables and equations needed as well as sample test cases to check the code against.

Uploaded by

hr.promosi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Problem Set due Jun 23, 2023 06:30 WIB Past due

Problem 1 - Paying Debt off in a Year


0.0/10.0 points (graded)
Write a program to calculate the credit card balance after one year if a person only pays the minimum monthly
payment required by the credit card company each month.
The following variables contain values as described below:
1. balance - the outstanding balance on the credit card
2. annualInterestRate - annual interest rate as a decimal
3. monthlyPaymentRate - minimum monthly payment rate as a decimal
For each month, calculate statements on the monthly payment and remaining balance. At the end of 12 months,
print out the remaining balance. Be sure to print out no more than two decimal digits of accuracy - so print
Remaining balance: 813.41

instead of
Remaining balance: 813.4141998135

So your program only prints out one thing: the remaining balance at the end of the year in the format:
Remaining balance: 4784.0

A summary of the required math is found below:


Monthly interest rate= (Annual interest rate) / 12.0
Minimum monthly payment = (Minimum monthly payment rate) x (Previous balance)
Monthly unpaid balance = (Previous balance) - (Minimum monthly payment)
Updated balance each month = (Monthly unpaid balance) + (Monthly interest rate x Monthly unpaid
balance)
We provide sample test cases below. We suggest you develop your code on your own machine, and make sure
your code passes the sample test cases, before you paste it into the box below.
Test Cases to Test Your Code With. Be sure to test these on your own machine - and that you get the same
output! - before running your code on this webpage!
Problem 1 Test Cases
Note: Depending on where you round in this problem, your answers may be off by a few cents in either direction.
Do not worry if your solution is within +/- 0.05 of the correct answer. Be sure to test these on your own machine -
and that you get the same output! - before running your code on this webpage!
Test Cases:
1. # Test Case 1:
balance = 42
annualInterestRate = 0.2
monthlyPaymentRate = 0.04

# Result Your Code Should Generate Below:


Remaining balance: 31.38

# To make sure you are doing calculation correctly, this is the


# remaining balance you should be getting at each month for this example
Month 1 Remaining balance: 40.99
Month 2 Remaining balance: 40.01
Month 3 Remaining balance: 39.05
i i
Month 4 Remaining balance: 38.11
Month 5 Remaining balance: 37.2
Month 6 Remaining balance: 36.3
Month 7 Remaining balance: 35.43
Month 8 Remaining balance: 34.58
Month 9 Remaining balance: 33.75
Month 10 Remaining balance: 32.94
Month 11 Remaining balance: 32.15
Month 12 Remaining balance: 31.38

2.
Test Case 2:
balance = 484
annualInterestRate = 0.2
monthlyPaymentRate = 0.04

Result Your Code Should Generate Below:


Remaining balance: 361.61

1 # Paste your code into this box


2

Press ESC then TAB or click outside of the code editor to exit
Unanswered
Hints
Only two decimal digits of accuracy?
Use the round function at the end of your code!
How to think about this problem?
To help you get started, here is a rough outline of the stages you should probably follow in writing your code:
For each month:
Compute the monthly payment, based on the previous month’s balance.
Update the outstanding balance by removing the payment, then charging interest on the result.
Output the month, the minimum monthly payment and the remaining balance.
Keep track of the total amount of paid over all the past months so far.
Print out the result statement with the total amount paid and the remaining balance.
Use these ideas to guide the creation of your code.

Important
Only hit "Check" once per submission. You only get 30 checks per problem.
** O t ti d tk f i t t d ith f db k If hit "Ch k" lti l ti
** Our automatic grader may take a few minutes to respond with feedback. If you hit "Check" multiple times, you
will lose a check for every press of the button.
** If you're unfamiliar with how our autograder works, first try out one of the infinite check problems in the
Functions lecture sequence.
** Please be judicious with your checks, as we are unable to give you more than 30 checks. However this should
be more than sufficient: if you do your code development in your local environment, and ensure you can pass our
test cases, you should not require more than a few checks once you paste your working, tested code into our
code box.
If you believe you have correct code but it is marked incorrect after clicking "Check"...
** After you submit your code, you can see every test case the graders runs on your code. They compare what
your code outputs with what our answer code is supposed to output. Click the small link titled "See Full Output"
below the Test Results header.
"Staff Debug: L397 Error" means your code has an infinite loop...
** Clicking Check may give you the error:
There was a problem running your solution (Staff debug: L379).
We couldn't run your solution (Staff debug: L397). .
This means your code is taking too long or has an infinite loop. Test your code with more unique test cases, such
as very large or very small values.
Do not define your own values
** For problems such as these, do not include input statements or define variables we told you would be given.
Our automated testing will provide values for you - so write your code in the following box assuming those
variables are already defined. The code you paste into the following box should not specify the values for the
variables balance , annualInterestRate , or monthlyPaymentRate

Submit You have used 0 of 30 attempts

Problem 1 - Paying Debt off in a Year Hide Discussion


Topic: Problem Set 2 / Problem 1
Show all posts by recent activity
 Randomized Test Case 4 11
My code is giving the correct answer for all but test case 4. My answer is rounded to two decimal places and the expected ans…
 summition pas due date 2
hi I missed the deadline day, i was having connection issue at my home for the past days, so how can I do it again
 Submit answers past date due 5
Hi, I missed the deadline for the exercise submission as my monitor broke down for the past 2 days. Is there any ways i can still …
 Completing Problem Set 2 a Little bit late 2
Hello there, I wanted to ask if I can still complete Problem Set 2 for my grade. My school ended a bit late and I was unable to co…
 Can not Submit my answer. 8
Why can't I turn this in? I was gone for a week and was not able to turn this in on the due date. Is this why it will not let me sub…
 Can I postpone the test/submission? 2
I just enrolled into the course but I can not start course immediately due to personal matter. Can I complete the course later and…
 Print out 3
the instructions say "Print out the result statement with the total amount paid and the remaining balance.", should we still make …
 Incorrect output 2
I put my code in the test box and it showed I had an incorrect output. But when I used it in Spyder it worked perfectly. Why is thi…
 why incorrect 2
I tested the code on my own machine, the output is exactly as the same as test cases. Why It indicated "incorrect" after running…

You might also like