Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Dictionaries: You may wish to write the code for parts ad in one Jupyter notebook. Consider the following two dictionaries: stock = {banana: 6, apple:

Dictionaries: You may wish to write the code for parts ad in one Jupyter notebook.

Consider the following two dictionaries:

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

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

a. Show the expression that gets the value of the stock dictionary at the key orange. Print out the results. Show a statement that adds an item to the stock dictionary called cherry with some integer value and that adds cherry to the prices dictionary with a numeric value. (Or pick your own fruit name.) Make sure you label and print your results.

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

c. Suppose that we have a list:

groceries = [apple, banana, pear]

Write the code that will sum the total number in stock of the items in the groceries list. How many apples + bananas + pears are there? Display the total items labeled appropriately.

d. Write the code that can print out the total value in stock of all the items. This program can iterate over the stock dictionary and for each item multiply the number in stock times the price of that item in the prices dictionary. (This can include the items for cherry or not, as you choose.) Display the total value with appropriate label and formatting of the total value in dollars.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes And Databases On The Internet A Practical Guide To Functions And Applications

Authors: Paul Rangel

1st Edition

189848631X, 978-1898486312

More Books

Students also viewed these Databases questions