listing3-1.py 572 B

1234567891011121314151617181920212223
  1. # Print a formatted price list with a given width
  2. width = int(input('Please enter width: '))
  3. price_width = 10
  4. item_width = width - price_width
  5. header_fmt = '{{:{}}}{{:>{}}}'.format(item_width, price_width)
  6. fmt = '{{:{}}}{{:>{}.2f}}'.format(item_width, price_width)
  7. print('=' * width)
  8. print(header_fmt.format('Item', 'Price'))
  9. print('-' * width)
  10. print(fmt.format('Apples', 0.4))
  11. print(fmt.format('Pears', 0.5))
  12. print(fmt.format('Cantaloupes', 1.92))
  13. print(fmt.format('Dried Apricots (16 oz.)', 8))
  14. print(fmt.format('Prunes (4 lbs.)', 12))
  15. print('=' * width)