python - 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。这里有什么问题?
解决方案
你在调用它时不小心颠倒了你的时间和速率参数。
您应该将其称为:
compound_interest(10000, 5, 10.25)
不是compound_interest(10000, 10.25, 5)
推荐阅读
- memory-leaks - IBM WebSphere - JVM 大小继续增长,而 GC 无济于事
- java - 如何在撒克逊语中扩展 doc() 功能
- swift - 自动更新订阅在沙盒中永不过期
- html - 覆盖 DIV 及其内外的链接
- amazon-web-services - 适用于 AWS.CloudWatchLogs 的 PutLogEvents API 的 nextSequenceToken 是什么
- node.js - 当我调用 admin.database() 时,每次都会在 firebase 中打开一个新的数据库连接吗?
- python - Pandas - 自上次以来的行号大于 0 值
- google-cloud-platform - 在控制台中更改 Google Cloud Compute Engine 实例的内部静态 IP 地址
- java - 如何检查元素是否存在于 LinkedList 的索引中
- java - OnitemClick 返回错误的字符串值