Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

# 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions