Learn to Code
John F. Dumas

Python - Making Change

► Problem Description: Given these denominations of coins: penny, nickel, dime, quarter, half-dollar and dollar, write a program that can output all the ways to make change for a given amount of money using those denominations. Below under the Source Code section, you'll find 'two-fifty.txt' which shows the 6,148 ways to make change for \$2.50.

► Example Output (amount: \$2.50):

```
1) 250 pennies
2) 245 pennies, 1 nickel
3) 240 pennies, 2 nickels
4) 235 pennies, 3 nickels
5) 230 pennies, 4 nickels
6) 225 pennies, 5 nickels
7) 220 pennies, 6 nickels
8) 215 pennies, 7 nickels
...
6141) 15 pennies, 1 dime, 1 quarter, 2 dollar-coins
6142) 10 pennies, 1 nickel, 1 dime, 1 quarter, 2 dollar-coins
6143) 5 pennies, 2 nickels, 1 dime, 1 quarter, 2 dollar-coins
6144) 3 nickels, 1 dime, 1 quarter, 2 dollar-coins
6145) 5 pennies, 2 dimes, 1 quarter, 2 dollar-coins
6146) 1 nickel, 2 dimes, 1 quarter, 2 dollar-coins
6147) 2 quarters, 2 dollar-coins
6148) 1 fifty-cent-piece, 2 dollar-coins
```

► Source Code

All files (zip file)

© John F. Dumas | johnfdumas@gmail.com | main page | top of page