#!/usr/bin/python def amort(cost, interest, term, pmt): mint = (1 + interest) ** (1.0/12) for i in range(term): for j in range(12): cost *= mint cost -= pmt return cost def findpmt(cost, interest, term): ub = cost lb = 0 test = cost / 2 bal = amort(cost, interest, term, test) while abs(bal) > 1000: if bal > 0: lb = test else: ub = test test = (lb + ub)/2 bal = amort(cost, interest, term, test) return test def ira(down, pmt, interest, term): mint = (1 + interest) ** (1.0/12) for i in range(term): for j in range(12): down += pmt down *= mint return down