我在想办法让这些年的利息和本金正确地显示出来。以下是我遇到问题的代码部分:print ('Luke\n-----')
print ('Year\tPrincipal\tInterest\t Total')
LU_RATE = .05
YEAR = 1
Principal = 100
for YEAR in range (1,28):
# Calculating Luke's total using formula for compounding interest
Lu_Total = (Principal * ((1 + LU_RATE) ** YEAR))
# I realize it's a logical error occurring somewhere here
Lu_Interest = #I'm not sure what to code here
Lu_Principal = #And here
# Displaying the Principal, Interest, and Total over the 27
print (YEAR,'\t%.02f\t\t %.02f\t\t %.02f' %(Lu_Principal, Lu_Interest, Lu_Total))
以下是显示的内容(当然不包括注释符号):
^{pr2}$
我试着编写的每一个等式在第一年都有正确的利息,但最后却把本金作为总额。过去的每一年都计算出错误的数字。在
它应该看起来像:Luke
-----
Year Principal Interest Total
1 100.00 5.00 105.00
2 105.00 5.25 110.25
3 110.25 5.51 115.76
#etc etc....
我一整天都在断断续续地工作,只是好像搞不懂。提前感谢您的任何帮助或建议。在