問5
import math
def question5(tot):
V = [500, 100, 50, 10, 5, 1]
C = [10, 10, 10, 10, 10, 10]
ans = 0
for v, c in zip(V, C):
t = min(math.floor(tot / v), c)
tot -= t * v
print(v, "円硬貨", t, "枚")
ans += t
if t < 0:
return False
print("残額 ", tot)
if tot == 0:
return ans
else:
return False
x = 1672
question5(x)
500 円硬貨 3 枚
100 円硬貨 1 枚
50 円硬貨 1 枚
10 円硬貨 2 枚
5 円硬貨 0 枚
1 円硬貨 2 枚
残額 0
9
x = 5549
question5(x)
500 円硬貨 10 枚
100 円硬貨 5 枚
50 円硬貨 0 枚
10 円硬貨 4 枚
5 円硬貨 1 枚
1 円硬貨 4 枚
残額 0
24
x = 3067
question5(x)
500 円硬貨 6 枚
100 円硬貨 0 枚
50 円硬貨 1 枚
10 円硬貨 1 枚
5 円硬貨 1 枚
1 円硬貨 2 枚
残額 0
11
x = 8802
question5(x)
500 円硬貨 10 枚
100 円硬貨 10 枚
50 円硬貨 10 枚
10 円硬貨 10 枚
5 円硬貨 10 枚
1 円硬貨 10 枚
残額 2142
False
x = -124
question5(x)
500 円硬貨 -1 枚
False