python - 最小和最大功能来计算最小信用卡余额
问题描述
我正在尝试使用最小和最大函数编写 Python 代码来计算信用卡上的最小余额。它是这样计算的:。最低付款额等于客户余额的 10 美元或 2.1%,以较高者为准;但如果这超过了余额,那么最低付款就是余额。这是我的代码:
如果余额是 600 balance = 600 customerInterest = max((balance*0.021),10.00) print(customerInterest) 如果余额是 11 balance = 11 customerInterest = min(max((balance * 0.021, 10.00)), balance) print (客户兴趣)
解决方案
使用 Python 3(示例客户余额为 543.21 美元):
from decimal import *
def calculateMinPayment(customerBalance: Decimal) -> Decimal:
if not isinstance(customerBalance, Decimal):
raise TypeError('unsupported parameter type for customerBalance')
return min(max(Decimal('10'), customerBalance * Decimal('0.021')), customerBalance).quantize(Decimal('.01'), rounding=ROUND_HALF_UP)
print(calculateMinPayment(Decimal('543.21')))
推荐阅读
- performance - Raku 慢速混合排序
- deep-learning - 模型之间的巨大精度差异
- android - 如何将背景图片正确添加到 MaterialCardView
- debugging - 如何修复 NuxtJs 控制台错误
- html - Outlook 更改 HTML 表格间距
- python - 删除列表内列表中的最后一项,然后将值添加到列表中的列表
- linqpad - 如何使用 Entity Framework Core 将 Oracle NUMBER(1) 映射到 LinqPad 6 中的整数而不是布尔值?
- javascript - 如何在加载下一个之前淡出标签内容 div?
- windows - 如何以编程方式更改 Windows NIC 驱动程序的参数?
- node.js - 如何使用函数参数获取node.js中json文件的数据