Question: Help with Project Python Shopping List: Data Structure The structure of the data for this project is extremely important. Each grocery item is a dictionary
Help with Project Python Shopping List:
Data Structure
The structure of the data for this project is extremely important.
Each grocery item is a dictionary with the following key-value pairs
a name of the grocery item with the key identifier 'name'
the number of grocery items purchased with the key identifier 'number'
the cost of the grocery item with the key identifier 'price'
{'name': 'milk', 'number': int(1), 'price': float(2.99)}
grocery_history is a list of grocery item dictionary elements.
grocery_history=[{'name': 'milk', 'number': int(1), 'price': float(2.99)},
{'name': 'eggs', 'number': 2, 'price': 3.99},
{'name': 'onions', 'number': 4, 'price': 0.79}]
Control Structure
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: "
------------------------------------------
Single Item Check Input:
milk 1 2.99 q
Expected Output:
Item name: Quantity purchased:
Price per item: Would you like to enter another item?
Type 'c' for continue or 'q' to quit:
1 milk @ $2.99 ea $2.99
Grand total: $2.99
Multiple Item Check Input:
milk
1
2.99
c
eggs
2
3.99
c
onions
4
0.79
q
Expected Output:
Item name:
Quantity purchased:
Price per item:
Would you like to enter another item?
Type 'c' for continue or 'q' to quit:
Item name:
Quantity purchased:
Price per item:
Would you like to enter another item?
Type 'c' for continue or 'q' to quit:
Item name:
Quantity purchased:
Price per item:
Would you like to enter another item?
Type 'c' for continue or 'q' to quit:
1 milk @ $2.99 ea $2.99
2 eggs @ $3.99 ea $7.98
4 onions @ $0.79 ea $3.16
Grand total: $14.13
------------------------------------------
'''
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 quantitiy 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
