A man has a rather old car being worth $2000. He saw a secondhand car being worth $8000. He wants to keep his old car until he can buy the secondhand one.
He thinks he can save $1000 each month but the prices of his old car and of the new one decrease of 1.5 percent per month. Furthermore the percent of loss increases by a fixed 0.5 percent at the end of every two months.
解法:
def nbMonths(oc, nc, sm, p):
m=0
while oc-nc+sm*m<0:
m+=1
q=1-p*0.01-(0.5*0.01*(m//2))
oc*=q
nc*=q
return [m,round(oc-nc+sm*m)]