我正在尝试创建一个程序,询问用户他们的本金,利率和总年数。我希望我的计划向他们展示他们每年的总回报金额。我希望它从第1年开始。当我运行我的剧本时,它只显示一年的总价值。这是我到目前为止所拥有的。
#Declare the necessary variables.
princ = 0
interest = 0.0
totYears = 0
year = 1
#Get the amont of principal invested.
print("Enter the principal amount.")
princ = int(input())
#Get the interest rate being applied.
print("Enter the interest rate.")
interest = float(input())
#Get the total amount of years principal is invested.
print ("Enter the total number of years you're investing this amonut.")
totYears = int(input())
for years in range(1, totYears):
total=year*interest*princ
years += 1
print (total)
谢谢你的任何帮助表示赞赏。
答案 0 :(得分:1)
这里有问题:
for years in range(1, totYears):
total=year*interest*princ
years += 1
print (total)
也许你需要这个:
for years in range(1, totYears):
total = years * interest * princ
print (total)