I'm having a bit of trouble with a problem from an online course (Introductory Python). Essentially, we are told to use binary search to find the lowest fixed payment each month to clear out a debt in a year (rounded to the nearest $0.01), when given a balance and an annual interest rate. My solution, when uploaded to their online grader, gives me only this error:
"There was a problem running your solution. We couldn't run your solution."
Am I possibly in an infinite loop? If so, I don't quite see how. The original code is posted below. Thank you all for taking the time to read this!
MonthlyInterestRate = annualInterestRate/12
month = 1
LB = balance/12
UB = balance*(2.7/12)
check = balance
while abs(balance) > 10:
payment = (LB + UB)/2
while month <= 12:
balance = (balance - payment)*(1 + MonthlyInterestRate)
month = month + 1
if balance > 10:
LB = payment
balance = check
elif balance < -10:
UB = payment
balance = check
else:
print('Lowest Payment: ' + str(payment))
break
annualInterestRateorbalanceanywhere.MonthlyInterestRate = annualInterestRate/12is wrong if there is a compounding) 4. Use integers or decimal.Decimal for arithmetic on money.