Skip to content

Instantly share code, notes, and snippets.

@uranusjr
Created May 30, 2015 23:48
Show Gist options
  • Save uranusjr/38396391bf91b45b1d40 to your computer and use it in GitHub Desktop.
Save uranusjr/38396391bf91b45b1d40 to your computer and use it in GitHub Desktop.
Starting point for the accountant project.
def _show_items(items):
template = '{name:20}{price:>5}'
if not items:
print("No items. Use 'add' to add some!")
return
print()
print(template.format(name='Item', price='Price'))
print('-' * 25)
for item in items:
print(template.format(
name=item['name'], price=item['price'],
))
print()
def add():
items = []
name = input('Item name: ')
price = input('Price: ')
if name and price:
items.append({
'name': name, 'price': price,
})
_show_items(items)
if __name__ == '__main__':
add()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment