首页 > 编程知识 正文

Python 程序:计算复利

时间:2023-11-24 15:33:37 阅读:308794 作者:MJAC

用例子写一个计算复利的 Python 程序。在我们开始 Python 复利程序之前,让我向您展示复利背后的公式:

未来 CI =本金金额* ( 1 + ROI ) 年数 )

上述计算称为未来复利。因为它包含本金和配置项。获取复利:复利=未来配置项-本金

计算复利的 Python 程序

这个 python 程序允许用户输入本金金额、利率和时间段(年数)。使用这些值, Python 使用上面指定的公式计算复利。

import math

princ_amount = float(input(" Please Enter the Principal Amount : "))
rate_of_int = float(input(" Please Enter the Rate Of Interest   : "))
time_period = float(input(" Please Enter Time period in Years   : "))

ci_future = princ_amount * (math.pow((1 + rate_of_int / 100), time_period)) 
compound_int = ci_future - princ_amount

print("Future Compound Interest for Principal Amount {0} = {1}".format(princ_amount, ci_future))
print("Compound Interest for Principal Amount {0} = {1}".format(princ_amount, compound_int))

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。