Better alternative.

cointype = (100, 10, 5, 1, 0.5)

def coins(fin):
        needed = {}
        for c in cointypes:
                v, r = divmod(fin, c)
                if v > 0:
                        needed[c] = v
                        fin = r
        return needed

if __name__ == '__main__':
        print coins(51)
        print coins(127)
        print coins[12.5)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to