Grocery List Requirements
Grocery List Requirements
Grocery List Requirements
Control Structure
The variable stop will be used with a while loop to check if the loop condition is true
(and the loop will continue) or if the loop condition is false (and the loop will exit).
In this script, the loop will end when the user enters ‘q’
As the code in the while loop should run at least once, set the stop variable to anything
other that 'q’, e.g. 'go' or True
stop = 'go'
Write a loop that will be used to collect user input.
The While loop will use the stop variable to determine if the user has completed entering their grocery
items.
The following steps will all be completed if the loop condition is met (i.e., the user
has not entered 'q' ):
1. Accept input of the name of the grocery item purchased.
Prompt: "Item name:\n"
Variable: item_name
Prompt: "Quantity purchased:\n"
Variable: quantity
3. Accept input of the cost of the grocery item input (this is a per-item cost).
4. Create a dictionary entry in the loop which contains the name, number and
price entered by the user. Assign the entry to a variable named grocery_item
5. Add the grocery_item to the grocery_history list using the append function
6. Prompt the user for input asking if they have finished entering grocery items.
Use the prompt:
"Would you like to enter another item?\nType 'c' for continue or 'q' to quit:\n"
2. 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'
c. Output the information for the grocery item to match this example:
3. Finally, after printing all the items, print the grand total!
i. Creating lists
B. Create examples of four uses of dictionary operations in your code. Be sure your examples address
each of the following:
i. Creating dictionaries
C. Create examples of three uses of loop structures in your code. Be sure your examples address each of
the following: