Ask Question

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

+3
Answers (1)
  1. 15 February, 09:48
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers