Created
February 7, 2016 18:21
-
-
Save krysseltillada/e94f9255eb4d208be524 to your computer and use it in GitHub Desktop.
MIT6_00SCS11_ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def minMonthPayment (minMonthRate, Balance): | |
return minMonthRate * Balance | |
def interestPaid (AnnualRate, Balance): | |
return AnnualRate / 12.0 * Balance | |
def principalPaid (minMonthPay, interestPaid): | |
return minMonthPay - interestPaid | |
def remainingBalance (Balance, principalPaid): | |
return Balance - principalPaid | |
def printDetails (mininumPayment, interestPd, principalPd, remainingBal, month): | |
print ("month " + str (month + 1)) | |
print ("Mininum monthly payment: $" + str ( round (mininumPayment, 2))) | |
print ("Principle Paid: $" + str ( round (principalPd, 2))) | |
print ("Remaining Balance: $" + str ( round (remainingBal, 2))) | |
def calculateDebt (Balance, AnnualRate, mininumRate): | |
month = 0 | |
prevBal = 0.0 | |
totalPaid = 0.0; mininumPayment = 0.0; interestPd = 0.0 | |
principalPd = 0.0; remainingBal = 0.0 | |
for month in range (12): | |
if (month == 0): | |
mininumPayment = minMonthPayment (mininumRate, Balance) | |
interestPd = interestPaid (AnnualRate, Balance) | |
principalPd = principalPaid (mininumPayment, interestPd) | |
remainingBal = remainingBalance (Balance, principalPd) | |
prevBal = remainingBal | |
else: | |
mininumPayment = minMonthPayment (mininumRate, prevBal) | |
interestPd = interestPaid (AnnualRate, prevBal) | |
principalPd = principalPaid (mininumPayment, interestPd) | |
remainingBal = remainingBalance (prevBal, principalPd) | |
prevBal = remainingBal | |
totalPaid += interestPd + principalPd | |
printDetails (mininumPayment, interestPd, principalPd, remainingBal, month) | |
print ("Result") | |
print ("Total Amount Paid: " + str ( round (totalPaid, 2))) | |
print ("Remaining Balance: " + str ( round (remainingBal, 2))) | |
Balance = 0.0 | |
AnnualRate = 0.0 | |
mininumRate = 0.0 | |
Balance = float(input("enter your current balance in your credit card: ")) | |
AnnualRate = float(input("enter your annualRate: ")) | |
mininumRate = float(input("enter your mininumRate: ")) | |
calculateDebt (Balance, AnnualRate, mininumRate) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment