167k views
5 votes
Grocery_List

1 Create dictionary with a grocery list. Assign the dictionary to the variable grocery_list
2 Print out the contents of grocery_list, one item at a time, in the order: name, cost, quantity.
3 Update the quantity to 3
4 Print out the contents of grocery_list, one item at a time, in the order: name, cost, quantity, after the quantity update.

provided:

# Create dictionary with a grocery list. Assign the dictionary to the variable grocery_list

# Print out the contents of grocery_list

# Update the quantity to 3

# Print out the contents of grocery_list after updating the quantity

User Woof
by
5.3k points

2 Answers

3 votes

Answer:

2

Step-by-step explanation:

User Vectoria
by
5.5k points
5 votes

Answer:

Following are the program in the Python Programming Language.

#set dictionary and initialize value

grocery_list ={"name":"Bread", "Cost": 27, "quantity":2}

#print name of the product

print( "Grocery: ",grocery_list['name'])

#print cost of the product

print("Cost: ",grocery_list['Cost'])

#print quantity of the product

print("Quantity",grocery_list['quantity'])

#update the quantity and cost

grocery_list['quantity'] = 3

grocery_list['Cost'] =40

print()#for space

#print name of the product

print( "Grocery: ",grocery_list['name'])

#print cost of the product after update

print("Cost: ",grocery_list['Cost'])

#print quantity of the product after update

print("Quantity",grocery_list['quantity'])

Output:

Grocery: Bread

Cost: 27

Quantity 2

Product: Bread

Cost: 40

Quantity 3

Step-by-step explanation:

Here, we define the dictionary type variable "grocery_list" and initialize values in it.

  • Then, print the name of the grocery.
  • Then, print the cost of the following product.
  • Then, print quantity of the grocery.
  • Then, we update the quantity and cost.

Finally, we again print the following thing after the update.

User Ruger
by
5.4k points