31.py 620 B

123456789101112131415161718192021222324252627
  1. # Global variables. Total is £2, so 200 pence.
  2. total = 200
  3. ways = 0
  4. # a is 200p
  5. # b is 100p
  6. # c is 50p
  7. # d is 20p
  8. # e is 10p
  9. # f is 5p
  10. # g is 2p
  11. # h is 1p
  12. # Loop goes through each coin from the total to the amount left stored in the
  13. # previous variable to 0, and decreases the amount left with the value of the
  14. # coin. Each loop increases the number of ways by one.
  15. for a in range(total, -1, -200):
  16. for b in range(a, -1, -100):
  17. for c in range(b, -1, -50):
  18. for d in range(c, -1, -20):
  19. for e in range(d, -1, -10):
  20. for f in range(e, -1, -5):
  21. for g in range(f, -1, -2):
  22. ways += 1
  23. print(ways)