繁体   English   中英

min 和 max 函数来计算最低信用卡余额 [关闭]

[英]min and max funcion to calculate minimum credit card balance [closed]

我正在尝试使用最小和最大函数编写 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')))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM