python 코딩 에러(도와주세요..ㅠ)
글쓴이: skyline066 / 작성시간: 토, 2017/04/15 - 7:35오후
실행은 되는데 오류이런것도 없는데 아무값도 안뜨네요.. 어디가 잘못된거죠
def coinChange2(coinValueList, total, numCoins, coinDict): if total == 0: return (numCoins, coinDict) bestCoins = -1 bestDict = {} for i in range(len(coinValueList)): dictCopy = {} for coin in coinValueList: dictCopy[coin] = coinDict[coin] coin = coinValueList[i] if coin <= total: dictCopy[coin] += 1 (subCoins, subDict) = coinChange2(coinValueList, total - coin, numCoins + 1, dictCopy) if bestCoins == -1 or subCoins < bestCoins: bestCoins = subCoins bestDict = subDict return (bestCoins, bestDict) if __name__=='__main__' : total = 205 coins = [1, 10, 50, 100, 500] baseDict = {} for coin in coins: baseDict[coin] = 0 numCoins = coinChange2( coins, total, 0, baseDict) print ("Total Amount : ", total) print ("동전의 갯수: ", coins) for coin in coins: print ("%d원동전:"%coin, numCoins[coin], end=', ') print() coins2 = [1, 10, 50, 100, 160, 500] numCoins2 = coinChange2(coins, total, 0, baseDict) print ("Total Amount : ", total) print ("동전의 갯수: ", coins) for coin2 in coins2: print ("%d원동전:"%coin2, numCoins2[coin2], end=', ') print()
Forums:
해결
해결했습니다
어떻게
어떻게 해결 하셨나요?
댓글 달기