使用一组输入值和固定利率构建计算器

问题描述

假设我每周做生意,每周以5%的恒定利率赚钱,并且假设我的投资每周递归,那么我想打印前21周的所有值。我如何在python中纠正代码以实现此目的? 注意:投资是递归的,(即)每周我的投资将是前一周的投资加上当周的利润,我也是四舍五入的值,我已经编写了这段代码,但是对于For循环,我在努力编写逻辑,可以请有人帮忙。我已经在excel中编写了逻辑/计算-请检查excel屏幕截图的预期结果。

maximum_number_of_weeks = int(input("maximum_number_of_weeks:"))
Initial_investment_Amount = int(input("Enter Initial Investment Amount Value ($) : "))
Interest_rate = float(input("Enter Interest Rate Value (%) : "))
Amount_Earned = Initial_investment_Amount * Interest_rate
Total_Amount_at_Disposal = Initial_investment_Amount + Amount_Earned
print("Total_Amount_at_Disposal ($) : ",Total_Amount_at_Disposal)

enter image description here

enter image description here

解决方法

我建议使用更简单的方法:

可支配金额=初始投资*(1 +利率)^(周数)

maximum_number_of_weeks = int(input("maximum_number_of_weeks:"))
Initial_investment_Amount = int(input("Enter Initial Investment Amount Value ($) : "))
Interest_rate = float(input("Enter Interest Rate Value (%) : "))

for week in range(1,maximum_number_of_weeks + 1):
    Total_Amount_at_Disposal = Initial_investment_Amount * (1 + Interest_rate/100) ** week
    print("Total_Amount_at_Disposal ($) : ",round(Total_Amount_at_Disposal,2))

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...