|
发表于 2021-6-2 10:38:53
|
显示全部楼层
输入大于 10 的数值就行:
- width = int(input('Please enter width:'))
- price_width = 10
- item_width = width - price_width
- header_fmt = '{{:{}}}{{:>{}}}'.format(item_width, price_width)
- fmt = '{{:{}}}{{:>{}.2f}}'.format(item_width, price_width)
- print('=' * width)
- print(header_fmt.format('Item', 'Price'))
- print('-' * width)
- print(fmt.format('Apples', 0.4))
- print(fmt.format('Pear', 0.5))
- print(fmt.format('Cantaloupes', 1.92))
- print(fmt.format('Dried Apricots (16 oz.)', 8))
- print(fmt.format('Prunes (4 1bs.)', 12))
- print('=' * width)
复制代码 |
|