编写一个程序,读取投资金额、年利率和年数,并使用以下公式显示未来的投资价值:FutureInvestmentValue = InvestmentAmount * (1 + monthlyInterestRate)NumberOfYears*12
时间: 2024-10-16 11:22:47 浏览: 12
编写一个简单的Python程序来计算未来投资值,可以按照您提供的公式进行。假设`monthlyInterestRate`是年利率除以12:
```python
def calculate_future_investment_value(investment_amount, annual_interest_rate, years):
# 将年利率转换为月利率
monthly_interest_rate = annual_interest_rate / 12
# 使用公式计算未来投资值
future_investment_value = investment_amount * (1 + monthly_interest_rate)**(years * 12)
return future_investment_value
# 示例输入
investment_amount = float(input("请输入投资金额(元): "))
annual_interest_rate = float(input("请输入年利率(百分比): ")) / 100 # 转换为小数形式
years = int(input("请输入投资年限: "))
future_value = calculate_future_investment_value(investment_amount, annual_interest_rate, years)
print(f"未来的投资价值为: {future_value} 元")
阅读全文