明確な範囲で最後の値を出力する方法は?
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
ループの最後の繰り返しだけを印刷するにはどうすればよいですか?