loan - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: loan (/thread-17222.html) |
RE: loan - mcgrim - Apr-07-2019 I totally understand what you are writing, and that's what I do if I already have all four values and want to find out the balance after n years. But now I need to calculate A, so I cannot write what it is if the code is supposed to find out. So the question is: how do I calculate A? RE: loan - ichabod801 - Apr-07-2019 (Apr-07-2019, 12:00 PM)mcgrim Wrote: All I am trying to do is to calculate A, how large does it need to be in order for the last element This will tell you the balance after n years: def f(balance, r, A, n): for year in range(n): balance = balance * (r / 100.0 + 1) - A return balanceIf you want to calculate A such that the balance is positive using this, you would need to run it with different values of A until you got a positive balance. RE: loan - micseydel - Apr-07-2019 I think ichabod's post is very useful, but I will also say that you may want to Google "binary search" as it seems well-suited to your problem. RE: loan - ichabod801 - Apr-07-2019 Well, there's also a simple formula that solves this problem. RE: loan - mcgrim - Apr-08-2019 to ichabod801: The code you wrote above is the one I already had. I totally understand what you are saying but perhaps you misunderstood my question. I am actually looking to write a code where A is an output. Makes sense? RE: loan - mcgrim - Apr-08-2019 what would be the formula for A ? If you believe you cannot give me a straight answer, may you perhaps write a code concerning something similar ? RE: loan - ichabod801 - Apr-08-2019 It's a load calculation. Do a web search for the formula for loan payments and you'll find it. RE: loan - mcgrim - Apr-08-2019 I don't need a new formula, I am using the one I have, I just have to change it in a way so A is the output, but I don't know how. On the interned I can only find different formulas for the loan payment, not exactly this one, and no formula found returns A. If you are aware of a website that has what I need, please share. RE: loan - ichabod801 - Apr-08-2019 (Apr-08-2019, 08:48 PM)mcgrim Wrote: On the interned I can only find different formulas for the loan payment, not exactly this one, and no formula found returns A. 'A' is the loan payment. RE: loan - mcgrim - Apr-08-2019 not exactly. A is a fixed amount that is paid every year. Every year you pay something from which A is subtracted (see formula on the code) |