Question: How do I fix this error? Traceback (most recent call last): File TEST, line 25, in print('%d %s @ $%.2f ea $%.2f' % (item['number'], item['name'],

How do I fix this error?

Traceback (most recent call last): File "TEST", line 25, in print('%d %s @ $%.2f ea $%.2f' % (item['number'], item['name'], item['price'], 'item_total')) TypeError: tuple indices must be integers, not str

How do I fix this error? Traceback (most recent call last): File

# creating dictionary/list grocery_item = {} grocery_history = [] # setting parameters to signal when to exit the Loop. stop = False while not stop: name = input("Item name: ") quantity = input("item quantity: ") cost = input("Price per item: ") # dictionary entry grand_total = 0 grocery_item = {'item_name': name, 'quantity': int(quantity), 'cost': float(cost)} grocery_history.append(grocery_item) stop = input('Would you like to enter another item? Type l'al' for continue or l'al' to quit: ') for item in enumerate(grocery_history): # finding the total cost of an item item_total = 0 #item_total = item['quantity'] * item ['cost'] # finding the grand total of all items grand_total = grand_total + item_total # %d - placeholder for quantity %s - placeholder for apple print("%d %s @ $%.2f ea $%.2f' % (item['number'], item['name'], item['price'], 'item_total')) print('Grand total: $%.2f' % grand_total)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!