我正在尝试使用最小和最大函数编写Python代码来计算信用卡上的最小余额。它计算如下:最低付款额等于客户余额的10美元或2.1%,以较高者为准;但如果超过余额,那么最低付款就是余额。这是我的代码:
如果余额为600余额= 600 customerInterest = max((余额* 0.021),10.00)print(customerInterest)如果余额为11 balance = 11 customerInterest = min(max((余额* 0.021,10.00)),余额)打印(customerInterest)
使用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')))