Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用于计算最低信用卡余额的最小和最大函数_Python_Function_Max_Min - Fatal编程技术网

Python 用于计算最低信用卡余额的最小和最大函数

Python 用于计算最低信用卡余额的最小和最大函数,python,function,max,min,Python,Function,Max,Min,我试图编写Python代码,使用最小值和最大值函数来计算信用卡上的最小余额。它是这样计算的:。最低付款额等于客户余额的10美元或2.1%,以较大者为准;但如果超过余额,则最低付款额为余额。这是我的密码: 如果余额是600 余额=600 customerInterest=最大值(余额*0.021),10.00) 打印(客户兴趣) 如果余额是11 余额=11 customerInterest=最小值(最大值((余额*0.021,10.00)),余额) 使用Python 3打印(customerInt

我试图编写Python代码,使用最小值和最大值函数来计算信用卡上的最小余额。它是这样计算的:。最低付款额等于客户余额的10美元或2.1%,以较大者为准;但如果超过余额,则最低付款额为余额。这是我的密码:

如果余额是600 余额=600 customerInterest=最大值(余额*0.021),10.00) 打印(客户兴趣) 如果余额是11 余额=11 customerInterest=最小值(最大值((余额*0.021,10.00)),余额) 使用Python 3打印(customerInterest)

(示例客户余额为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')))