python用is_vaild_withdrawal(amount)

img


if=10,50,20:
true
else:
False
这样思路去写嘛

就是先判断对10或20 或50余数是否为0 ,是再算具体所需的数量

img

def is_vaild_withdrawal(amount):
    if amount<=10:
        print('False')
    elif amount%10==0 or amount%20==0 or amount%50==0 :
        a=amount//50
        amount-=a*50
        b=amount//20
        amount-=b*20
        c=amount//10
        print(str(a)+' of $50, '+str(b)+' of $20, '+str(c)+' of $10')
        return('True')
    else:
        return('False')
s=int(input())
print(is_vaild_withdrawal(s))


def is_vaild_withdrawal(amount):
    if (amount % 50 == 0 or amount % 20 == 0 or amount % 10 == 0) and (amount >= 10):
        n_50 = amount // 50
        amount = amount % 50
        n_20 = amount // 20
        amount = amount % 20
        n_10 = amount // 10
        print("{} of $50,{} of $20, {} of $10".format(n_50,n_20,n_10))
        print(True)
    else:
        print(False)

is_vaild_withdrawal(135)
is_vaild_withdrawal(40)
is_vaild_withdrawal(210)
is_vaild_withdrawal(4)

img


如有帮助,点一下下采纳

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632