0

Given a positive integer change, a set of coins makes change for change if the sum of the values of the coins is change. We will use standard US Coin values: 1, 5, 10, 25.

I was asked to solve this coin change question with recursion function only(while and for loop are not allowed), and I am very struggling with it. Please help!

def next_smaller_coin(coin):
    """Returns the next smaller coin in order."""
    if coin = 25:
        return 10
    elif coin = 10:
        return 5
    elif coin = 5:
        return 1
      
def count_coins(change):
    if change == 0:
        return 1
    elif change < 0:
        return 0
    else:
        with_coin = count_coins(change - next_smaller_coin(coins))
        wo_coin = count_coins(change)
        return with_coin + wo_coin
Will Ness
  • 70,110
  • 9
  • 98
  • 181
Phyllis
  • 1
  • 2
  • Please be more explicit with what you are stuck on. BTW: `if coin = 25:` should be `if coin == 25:` – Matt Clarke Sep 22 '22 at 05:42
  • I once posted an explanation [here](https://stackoverflow.com/a/27804489/849891). there's some pseudocode in the answer. – Will Ness Sep 22 '22 at 07:35

0 Answers0