首页 > 解决方案 > Python。代码输出错误的答案。数学相关

问题描述

    def compound_interest(principle, time, rate):
    
        amount = principle * (pow((1 + rate / 100), time))
        return amount - principle

print('The compound interest is: ', compound_interest(10000, 10.25, 5))

输出应该是 6288.946267774416 但我得到的是 6488.848034974573。这里有什么问题?

标签: python

解决方案


你在调用它时不小心颠倒了你的时间和速率参数。

您应该将其称为:

compound_interest(10000, 5, 10.25)

不是compound_interest(10000, 10.25, 5)


推荐阅读