class Entry: def __init__(self, value, name, namePlural): self.mValue = value self.mName = name self.mNamePlural = namePlural def toString(self): return("value: {0}, name: {1}, namePlural: {2}".format(self.mValue, self.mName, self.mNamePlural)) class Change: def __init__(self): self.mList = [] def add(self, value, name, namePlural = ""): self.mList.append(Entry(value, name, name + "s" if namePlural == "" else namePlural)) def dump(self): for entry in self.mList: print(entry.toString()) def increment(counts, list, total): i = 0 n = len(counts) while i < n: counts[i] += 1 theValue = counts[i] * list[i].mValue if counts[i] * list[i].mValue <= total: return(True) counts[i] = 0 i += 1 return(False) def showCombinations(self, total): number = 1 counts = [] n = len(self.mList) for i in range(0, n): counts.append(0) while True: sum = 0 for i in range(0, n): sum += counts[i] * self.mList[i].mValue if sum == total: txt = "" for i in range(0, n): if counts[i] > 0: if txt != "": txt += ", " txt += "{0} {1}".format(counts[i], \ self.mList[i].mName if counts[i] == 1 else self.mList[i].mNamePlural) print("{0}) {1}".format(number, txt)) number += 1 if not Change.increment(counts, self.mList, total): break # ----------------------------- # Script Begins Here # ----------------------------- object = Change() object.add(1, "penny", "pennies") object.add(5, "nickel") object.add(10, "dime") object.add(25, "quarter") object.add(50, "fifty-cent-piece") object.add(100, "dollar-coin") object.showCombinations(250)