Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grocery_history = []
- stop = 'go'
- while stop != 'q':
- grocery_item = {}
- item_name = input ("Item name:\n")
- quantity = input ("Quantity purchased:\n")
- cost = input ("Price per item:\n")
- grocery_item['name'] = item_name
- grocery_item['number'] = int(quantity)
- grocery_item['price'] = float(cost)
- grocery_history.append(grocery_item)
- stop=input("Would you like to enter another item?\nType" + \
- "'c' for continue or 'q' to quit:\n")
- grand_total=0
- for element in grocery_history:
- item_total = element['number'] * element['price']
- grand_total += item_total
- #Output the information for the grocery item to match this example:
- #2 apple @ $1.49 ea $2.98
- print(f"{element['number']:>3} {element['name']:>10}\t" + \
- f"@\t${element['price']:>6.2f}\tea\t${item_total}")
- print(f'Grand total: ${grand_total}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement