我正在尝试使其代码返回的年份不同。 输入:
def rule_of_72():
view_percent = 1
percent = 0.01
value = 10
doubled = value * 2
years = 1
d = 0
while(d < value):
d = value * percent * years
years += 1
print("interest rate %", "Rule of 72", "Actual")
while(view_percent <= 20):
print(" ", view_percent, " ", 72//view_percent, " ", years - 1)
view_percent += 1
percent += 0.01
rule_of_72()
它不应该一直打印100张 它会打印出以年为单位的时间,以单利计算,它需要200倍的时间
我没人知道如何解决这个问题吗?
答案 0 :(得分:0)
您应该在第二个循环中更新年份,如下所示:
while(view_percent <= 20):
years=......
print(" ", view_percent, " ", 72//view_percent, " ", years - 1)
view_percent += 1
percent += 0.01
输入您的计算结果而不是......
答案 1 :(得分:0)
你是这个意思吗?
while(view_percent <= 20):
years -= 1
print(" ", view_percent, " ", 72//view_percent, " ", years)
view_percent += 1
percent += 0.01
输出:
interest rate % Rule of 72 Actual
1 72 100
2 36 99
3 24 98
4 18 97
5 14 96
6 12 95
7 10 94
8 9 93
9 8 92
10 7 91
11 6 90
12 6 89
13 5 88
14 5 87
15 4 86
16 4 85
17 4 84
18 4 83
19 3 82
20 3 81