소스 검색

Coin sums

Adel Qalieh 13 년 전
부모
커밋
2d6f6e50c1
1개의 변경된 파일27개의 추가작업 그리고 0개의 파일을 삭제
  1. 27 0
      31.py

+ 27 - 0
31.py

@@ -0,0 +1,27 @@
+# Global variables. Total is £2, so 200 pence.
+total = 200
+ways = 0
+
+# a is 200p
+# b is 100p
+# c is 50p
+# d is 20p
+# e is 10p
+# f is 5p
+# g is 2p
+# h is 1p
+
+# Loop goes through each coin from the total to the amount left stored in the
+# previous variable to 0, and decreases the amount left with the value of the
+# coin. Each loop increases the number of ways by one.
+
+for a in range(total, -1, -200):
+	for b in range(a, -1, -100):
+		for c in range(b, -1, -50):
+			for d in range(c, -1, -20):
+				for e in range(d, -1, -10):
+					for f in range(e, -1, -5):
+						for g in range(f, -1, -2):
+							ways += 1
+
+print ways