-1

I am trying to print a list that I ask my user to input. The program prints the list just fine but I want them to look nice and with correct spacing. How can I do this in Python? I want all the numbers aligned instead of having them this way:

Your list includes these items: 
Apples     2.10
Hamburger     3.25
Milk     3.49
Sugar     1.99
Bread     1.76
Deli Turkey     7.99
Pickles     3.42
Butter     2.79

1 Answers1

0

You can format your output:

for item, price in ('Apple', 2.10), ('Hamburger', 3.25):
    print('%-20s%10.2f' % (item, price))

This outputs:

Apple                     2.10
Hamburger                 3.25
blhsing
  • 91,368
  • 6
  • 71
  • 106