python - How can I find the credit card balance regarding my code? -


def balance (p, apr, mo): mpr = 0.01*apr/12 month in range(int(mo)):     p= p+p*mpr     return p 

i'm beginner trying create function return balance on credit card starting balance p , interest rate apr after mo months. when run code, seems loop not work.

 def balance (p, apr, mo):     mpr = 0.01*apr/12.0     month in range(int(mo)):         p= p+p*mpr     return p   in range(1,13):     print balance(1000,10,i) 

strictly mpr not correct (monthly compounding simplification justified in times before slide rules); monthly rate should 12th root of annual rate; see continous compounding https://en.wikipedia.org/wiki/compound_interest

def balance2 (p, apr, mo):     mpr =  ((1+apr/100.0)**(1/12.0)-1)     month in range(int(mo)):         p= p+p*mpr     return p  print  in range(1,13):     print balance2(1000,10,i)  

output:

1008.33333333 1016.73611111 1025.20891204 1033.75231964 1042.3669223 1051.05331332 1059.81209093 1068.64385836 1077.54922384 1086.52880071 1095.58320738 1104.71306744  1007.97414043 1016.01186777 1024.11368908 1032.28011546 1040.51166206 1048.80884817 1057.17219721 1065.60223677 1074.09949864 1082.66451888 1091.29783779 1100.0 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -