python 计算找零钱

#coding=gbk
#定义零钱种类
moneycount=[100,50,20,10,5,1]
def getMax(x):
    m=[]
    while True:
        for i in moneycount:
            if i<=x:
                x-=i
                m.append(i)
                break
        if x<1:
            break
    return m
a=getMax(298)
print(a)

练习一下算法

posted @ 2018-12-20 09:45  天天的蓝色  阅读(1788)  评论(0编辑  收藏  举报