Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this section you will loop through the grocery_history list. For each item, you will: Print the number of that item purchased Print the name

In this section you will loop through the grocery_history list. For each item, you will:
Print the number of that item purchased
Print the name of the item
Print the price paid for all of those items purchased
Add this price to the grand total for the entire list.
Your results will look similar to this:
2 Apple @ 1.49 ea $2.98
1 milk @ $3.99 ea $3.99
Grand total : $6.97
image text in transcribed
ection provide output to the conso Le #Task: Create the empty data structure grocery-item# {} grocery-history {} #variable used to check if the while loop condition is met stop go while stop : #Accept input of the name of the grocery item purchased. item-name input("milk") #Accept input of the quantity of the grocery item purchased. quantity int (input("1")) #Acceptinput of the cost of the grocery item input (this 1s a per-item cost). cost float (input (2.99)) #create a dictionary entry which contains the name , number and price entered by the user. grocery-item i {'name':iten-name, 'number' :quantity, 'price' :cost) # #Add the grocery-item to the grocery-history list using the append function grocery history.append (grocery item) Accept input from the user asking if they have finished entering grocery items. stop input("Do you need to enter another item?1nType 'c to continue or 'q' to quit:" # Define variable to hold grand total cated ,grand-total, grand total &Define a 'for' loop. for iten in range(o,Len(grocery_history)): Calculate the total cost for the grocery-item. iten-total (grocery-history[1tem] [.number'] Add the item-total to the grand-total grocery.history[iten]["price']) * grand-total tem-total #Output the information for the grocery item to match this example: #2 apple e $1.49 ea $2.98 print) #Set the item-total equal to iten total 0 #print the grand total print (grand total) Python

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions