Created
May 30, 2015 23:48
-
-
Save uranusjr/38396391bf91b45b1d40 to your computer and use it in GitHub Desktop.
Starting point for the accountant project.
This file contains 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
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