Question: This is using Python 3 Consider the following two dictionaries: stock = {banana:6,apple:0,orange:32,pear:15} prices={banana:4,apple:2,orange:1.5,pear:3} Show the expression that gets the value of the stock dictionary

This is using Python 3

Consider the following two dictionaries:

stock = {"banana":6,"apple":0,"orange":32,"pear":15}

prices={"banana":4,"apple":2,"orange":1.5,"pear":3}

Show the expression that gets the value of the stock dictionary at the key "orange". Add another item to the dictionary ("cherry", 14).

Write the code for a loop that iterates over the stock dictionary and prints each key and value.

Here is what I have come up with so far:

#create empty dictionaries

stock = { }

prices = { }

stock = {"banana":6,"apple":0,"orange":32,"pear":15}

prices={"banana":4,"apple":2,"orange":1.5,"pear":3}

for item in prices:

print (item)

print ("price: %s" % prices[item])

print ("stock: %s" % stock[item])

stock ['cherry'] = 14

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!