Description
What is important is developing the skill of learning how to understand your errors and then fix them (debugging). Explain the importance of knowing how and when to use lists, dictionaries, and loop types. Support your response with examples from the sample code below:
Two simple paragraphs.
# grocery_item
grocery_item = dict()
# grocery_history
grocery_history = list()
# go
go = True
# loop till go is true
while go:
# take input for item_name, quantity,cost
item_name = input("Item name:\n")
quantity = int(input("Quantity purchased:\n"))
cost = float(input("Price per item:\n"))
# update grocery_item with new data
grocery_item = {'name':item_name, 'number': int(quantity), 'price': float(cost)}
# append to list
grocery_history.append(grocery_item)
# ask user again for input
dt = input("Would you like to enter another item?\nType 'c' for continue or 'q' to quit:\n")
if dt == "q":
go = False # if q set go to False
grand_total = 0.0 # declare grand total
for each in grocery_history:
item_total = each['price']*each['number'] # cal item_total
# print details
print(str(each['number']) +" "+str(each['name']) + " @ $" +str('%.2f' % each['price'])+" ea $" + str('%.2f' % item_total))
# add item_total to grand_total
grand_total = grand_total + item_total
item_total = 0.0 # set item_total to 0
print("Grand total: $"+ str('%.2f' % grand_total))
Explanation & Answer
Attached.
What is important is developing the skill of learning how to understand your errors and then
fix them (debugging). Explain the importance of knowing how and when to use lists,
dictionaries, and loop types.
Debugging is an art which helps us understand the code better and fix errors in a strategic way.
Debugging lets us understand the behavior of code at every single point, thus ma...
Review
Review
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Similar Content
Related Tags
The Silent Patient
by Alex Michaelides
The Woman in the Window
by A. J. Finn
Dracula
by Bram Stoker
Notes from Underground
by Fyodor Dostoyevsky
The BFG
by Roald Dahl
Nervous Conditions
by Tsitsi Dangarembga
The Red Badge of Courage
by Stephen Crane
How to Win Friends and Influence People
by Dale Carnegie