Ask Question
12 July, 20:07

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

+2
Answers (1)
  1. 12 July, 21:43
    0
    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

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Grocery_List 1 Create dictionary with a grocery list. Assign the dictionary to the variable grocery_list 2 Print out the contents of ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers