def tooth(g): result = [] coins = [20, 10, 5, 1] def findCoinAmount(gramsLeft, coinIndex): result.append(gramsLeft//coins[coinIndex]) if coinIndex != len(coins) - 1: findCoinAmount(gramsLeft%coins[coinIndex], coinIndex+1) findCoinAmount(g, 0) return result if __name__ == "__main__": teeth = [95,103,71,99,114,64,95,53,97,114,109,11,2,21,45,2,26,81,54,14,118,108,117,27,115,43,70,58,107] prettyPrint = lambda tooth: print(f'20: {tooth[0]}, 10: {tooth[1]}, 5: {tooth[2]}, 1: {tooth[3]}') for grams in teeth: prettyPrint(tooth(grams))