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