Define a Python function calculate investment(P,r,n,t) that calculatesand returns the final amount after t years (Rounded to 2 decimal points).
时间: 2024-01-25 13:02:14 浏览: 107
Here's the Python function to calculate investment:
```python
def calculate_investment(P, r, n, t):
"""
Calculates the final amount after t years with principal P, interest rate r, compounded n times per year.
"""
A = P * (1 + (r/n))**(n*t)
return round(A, 2)
```
The parameters are:
- P: principal amount
- r: annual interest rate (as a decimal)
- n: number of times the interest is compounded per year
- t: number of years
The formula used to calculate the final amount is:
```
A = P * (1 + (r/n))**(n*t)
```
This formula takes into account the principle amount, the annual interest rate, the number of times the interest is compounded per year, and the number of years. The `round()` function is used to round the final amount to two decimal points as specified in the problem.
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)