Question: PYTHON CODING ASSISTANCE The task is broken down into three sections. Section 1 - User Input Section 2 - loop through the grocery list Section

PYTHON CODING ASSISTANCE

The task is broken down into three sections.

Section 1 - User Input

Section 2 - loop through the grocery list

Section 3 - provide output to the console

'''

#Task: Create the empty data structure

grocery_item = ?

grocery_history = ?

#Variable used to check if the while loop condition is met

stop = 'go'

while ?????? :

#Accept input of the name of the grocery item purchased.

#Accept input of the quantity of the grocery item purchased.

#Accept input of the cost of the grocery item input (this is a per-item cost).

#Create a dictionary entry which contains the name, number and price entered by the user.

#Add the grocery_item to the grocery_history list using the append function

#Accept input from the user asking if they have finished entering grocery items.

# Define variable to hold grand total called 'grand_total'

#Define a 'for' loop.

for ??????? in ?????????:

#Calculate the total cost for the grocery_item.

#Add the item_total to the grand_total

#Output the information for the grocery item to match this example:

#2 apple @ $1.49 ea $2.98

#Set the item_total equal to 0

#Print the grand total

TASKS ARE BELOW

-Create the empty data structure

-Create an empty dictionary with the variable name grocery_item

-Create an empty list with the variable name grocery_history

The following steps will all be completed if the loop condition is met (i.e., the user has not entered 'q'):

Accept input of the name of the grocery item purchased.

Prompt: "Item name: " Variable: item_name

Accept input of the quantity of the grocery item purchased.

Prompt: "Quantity purchased: " Variable: quantity

Accept input of the cost of the grocery item input (this is a per-item cost).

Prompt: "Price per item: " Variable: cost

Create a dictionary entry which contains the name, number and price entered by the user. Assign the entry to a variable named grocery_item

The format will be:

{'name':item_name, 'number': int(quantity), 'price': float(cost)}

Add the grocery_item to the grocery_history list using the append function

Prompt the user for input asking if they have finished entering grocery items. Use the prompt:

"Would you like to enter another item? Type 'c' for continue or 'q' to quit: "

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

Inside the for loop:

Define variable to hold grand total called grand_total

Define a 'for' loop. This loop will examine each element in the grocery_history list.

The loop will use the 'for in' convention. Each grocery_history list element will be assigned to a variable named 'grocery_item'

Output 2 apple @ $1.49 ea $2.98
Variable number name price item_total

Reminder

Your can use the %.2f formatting expression to format the dollar amounts

Calculate the total cost for the grocery_item.The calculation is:

item_total = number * price

Add the item_total to the grand_total

Output the information for the grocery item to match this example:

Set the item_total equal to 0

Finally, after printing all the items, print the 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!