如何打印确定范围内的最后一个值?
def main():
print "This program calculates the future value of a 10-year investment."
principal = input("Enter the initial principle: ")
apr = input("Enter the annual interest rate: ")
for i in range(10):
principal = principal * (1 + apr)
print "The value in 10 years is:", principal
输出:
The value in 10 years is XXXXXXX
The value in 10 years is XXXXXXX
The value in 10 years is XXXXXXX
The value in 10 years is XXXXXXX
The value in 10 years is XXXXXXX
The value in 10 years is XXXXXXX
The value in 10 years is XXXXXXX
The value in 10 years is XXXXXXX
The value in 10 years is XXXXXXX
The value in 10 years is XXXXXXX
如何仅打印循环的最后一次迭代?