Loan algorithm in Python