Last active
November 17, 2024 20:40
-
-
Save winzard/2636972beb1b3bad2d7e9e0792bb1d7e to your computer and use it in GitHub Desktop.
копилка с монетами
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # копилка с монетами | |
| coins = { | |
| '1': 3, '2': 5, '3': 10, '5': 4, '10': 2, '20':6 | |
| } | |
| # символы валюты | |
| money_symbol = '$$' | |
| max_len_coins = max(len(x) for x in coins.keys()) | |
| max_len_amount = max(len(str(x)) for x in coins.values()) | |
| max_len = max(max_len_coins, max_len_amount) # считаем максимальную ширину будущего столбца | |
| table = [] | |
| for j, k in coins.items(): | |
| padding_coins = str(j).ljust(max_len) | |
| padding_amount = str(k).ljust(max_len) | |
| for i, s in enumerate(padding_coins): | |
| table.append(s + '-' + money_symbol*k + padding_amount[i]) # выравниваем всё пока по горизонтали | |
| table.append(' -') | |
| else: | |
| del table[-1] | |
| max_height = max(len(x) for x in table) # самая длинная строка = высота столбца | |
| expanded_table = [x.ljust(max_height) for x in table] # делаем прямоугольник | |
| rotated = list(zip(*expanded_table)) # вращаем (вот тут я долго думал, как подставить параметры. Нужны несколько последовательностей на вход) | |
| for r in reversed(rotated): # печатаем сверху вниз | |
| print(''.join(r)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment