def compound_interest(num,start= 1,time=0,P=0,result=[]): N = num*P+num print('当前第'+start.__repr__()+'期,每期利率为'+P.__repr__()+',当前本息为:'+N.__repr__()) if time != 1: time -= 1 start += 1 result.append({
start-1:N}) return compound_interest(N,start,time,P) else: result.append({
start:N}) return result,N compound_interest(10000,time=12,P=0.003) compound_interest(float(compound_interest(20000,time=12,P=0.003)[-1]),t ...: ime=20,P=0.06)
num为本金
start 为初始次数值,默认为建议为0
time 为迭代次数
P为利息比例