def calculate_balance(balance, annualInterestRate, monthlyPaymentRate):
totalPaid = 0
remainingBalance = balance
for month in range(1,13):
monthlyInterestRate = annualInterestRate / 12.0
minimumMonthlyPayment = round((monthlyPaymentRate * remainingBalance),2)
totalPaid += minimumMonthlyPayment
monthlyUpaidBalance = remainingBalance - minimumMonthlyPayment
remainingBalance = round(monthlyUpaidBalance + (monthlyInterestRate * monthlyUpaidBalance),2)
print("Month: {}".format(month))
print("Minimum monthly payment: {}".format(minimumMonthlyPayment))
print("Remaining Balance: {}".format(remainingBalance))
print("Total paid: {}".format(totalPaid))
print("Remaining Balance: {}".format(remainingBalance))
calculate_balance(balance, annualInterestRate, monthlyPaymentRate)
Daily Archives: April 6, 2016
edX_MITx_6.00.1x/Problem_Set_2/Paying_Debt_Off_in_a_Year.py
def calculate_balance(balance, annualInterestRate):
monthlyInterestRate = annualInterestRate / 12.0
remainingBalance = balance
minimumMonthlyPayment = 0
while True:
minimumMonthlyPayment += 10
for _ in range(0,12):
monthlyUpaidBalance = remainingBalance - minimumMonthlyPayment
remainingBalance = round(monthlyUpaidBalance + (monthlyInterestRate * monthlyUpaidBalance),2)
if remainingBalance < 0:
break
else:
remainingBalance = balance
print("Lowest Payment: {}".format(minimumMonthlyPayment))
calculate_balance(balance, annualInterestRate)
edX_MITx_6.00.1x/Problem_Set_2/Bisection_Search.py
def calculate_balance(balance, annualInterestRate):
monthlyInterestRate = annualInterestRate / 12.0
lowerBound = balance / 12
upperBound = (balance * (1+ monthlyInterestRate)**12)/12
minimumMonthlyPayment = (upperBound + lowerBound)/2.0
while True:
remainingBalance = balance
for _ in range(0,12):
monthlyUpaidBalance = remainingBalance - minimumMonthlyPayment
remainingBalance = round(monthlyUpaidBalance + (monthlyInterestRate * monthlyUpaidBalance),2)
if remainingBalance <= 0 and remainingBalance >= -0.01:
break
else:
if remainingBalance > 0:
lowerBound = minimumMonthlyPayment
else:
upperBound = minimumMonthlyPayment
minimumMonthlyPayment = (upperBound + lowerBound)/2.0
print("Lowest Payment: {}".format(round(minimumMonthlyPayment,2)))
calculate_balance(balance, annualInterestRate)
edX_MITx_6.00.1x/Problem_Set_1/item_order.py
order = ""
def item_order(order):
salad = order.count("salad")
hamburger = order.count("hamburger")
water = order.count("water")
return("salad:{} hamburger:{} water:{}".format(salad, hamburger, water))
item_order(order)
edX_MITx_6.00.1x/Problem_Set_1/count_vowels.py
def count_vowels(s):
count = 0
for char in s:
if char in 'aeiou':
count += 1
print("Number of vowels: {}".format(count))
count_vowels(s)
edX_MITx_6.00.1x/Problem_Set_1/count_occurrence.py
def count_occurrence(s):
count = 0
pos = s.find("bob")
while pos != -1:
count += 1
pos = s.find("bob", pos+1)
print("Number of times bob occurs is: {}".format(count))
count_occurrence(s)