使用while循环计算利率



我正在做这个作业:

当银行出现财务问题时,政府可以返还a客户存款不足70万的,以客户存款为准。a的利率特别存款是每年7.1%。百分比支付给同样的存款在年底利息的新值是计算。

算出存款的金额需要多少年才能存入银行超过政府保护的价值

输入格式:

存款的初始金额。可以保证值将会在50,000到700,000之间。

输出格式:

年数。

下面是我得到的代码:
deposit = int(input())
year = 0
while deposit <= 700000:
deposit = (deposit * pow((7.1 / 100 + 1), year))
year += 1
print((year - 1))

它在我的IDE中工作,但网站一直坚持这是错误的。有什么问题吗?

如果我理解正确的话:

import math
rate = 7.1 / 100
limit = 700
deposit = int(input('Input deposit (50-700):'))
year = math.ceil(math.log(limit / deposit, rate + 1))
print(f'years to achieve {limit} = {year}')
print(f'checked sum of the deposit after {math.ceil(year)} years = {deposit * pow(rate + 1, year)}')

打印:

Input deposit (50-700):256
years to achieve 700 = 15
checked sum of the deposit after 15 years = 716.2786852658132

deposit = (deposit * (pow((1+7.1/100,year)))

最新更新