我正在尝试制作一个复利计算器,设法完成一项工作,但是现在我试图在其中添加一个部分,以便用户输入他们想要将其帐户存入的金额,然后找到直到他们达到了目标。我希望我的输出是该帐户中到达该货币所花费的年数加上前几年的所有输出的金额。我真的不确定如何为此循环,有帮助吗? 到目前为止的代码:
percent = float(input("Interest %: "))
Interest = float((percent + 100) / 100)
money = float(input("How much did you originally have in the bank?"))
num_years = float(input("How many years has it been in the bank?"))
Total_money = float((Interest ** num_years) * money)
while Total_money < 1000000:
num_years += 1
print([Total_money, num_years])
if Total_money >= 1000000:
break
答案 0 :(得分:0)
在进行for循环时,您需要更改total_money的金额:
percent = float(input("Interest %: "))
Interest = float((percent + 100) / 100)
money = float(input("How much did you originally have in the bank?"))
num_years = float(input("How many years has it been in the bank?"))
Total_money = float((Interest ** num_years) * money)
while Total_money < 1000000:
num_years += 1
Total_money *= Interest
print([Total_money, num_years])
if Total_money >= 1000000:
break
第Total_money *= Interest
行与:
Total_money = Total_money * interest
答案 1 :(得分:0)
这应该有效。
percent = float(input("Interest %: "))
Interest = float((percent + 100) / 100)
money = float(input("How much did you originally have in the bank?"))
num_years = float(input("How many years has it been in the bank?"))
n=0
while n < num_years:
Total_money = float((Interest ** n) * money)
n += 1
print(round(Total_money, 2), n)
if Total_money >= 1000000:
break