Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- change = int(float(input()) * 100)
- counter = 0
- while change > 0:
- if change >= 200:
- change -= 200
- elif change >= 100:
- change -= 100
- elif change >= 50:
- change -= 50
- elif change >= 20:
- change -= 20
- elif change >= 10:
- change -= 10
- elif change >= 5:
- change -= 5
- elif change >= 2:
- change -= 2
- elif change == 1:
- change -= 1
- counter += 1
- print(counter)
- Решение с тернарен оператор:
- change = int(float(input()) * 100)
- counter = 0
- while change > 0:
- change -= 200 if change >= 200 \
- else 100 if change >= 100 \
- else 50 if change >= 50 \
- else 20 if change >= 20 \
- else 10 if change >= 10 \
- else 5 if change >= 5 \
- else 2 if change >= 2 else 1
- counter += 1
- print(counter)
- Решение с лист:
- coins = [200, 100, 50, 20, 10, 5, 2, 1]
- change = int(float(input()) * 100)
- counter = 0
- for coin in coins:
- if change >= coin:
- counter += change // coin
- change %= coin
- print(counter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement