Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
10327 views
ubuntu2004
Kernel: Python 3 (system-wide)

Exercise 15.1

Create a dictionary called mushrooms containing the data in the following table. Print it.

Scientific NameCommon Name
Fistulina hepaticaBeefsteak
Laetiporus sulphureusChicken-of-the-Woods
Flammulina velutipesEnoki
Hericium erinaceusLion’s Mane
mushrooms = {'Fistulina hepatica':"Beefsteak", 'Laetiporus sulphureus':"Chicken-of-the-Woods", 'Flammulina velutipes': "Enoki", 'Hericium erinaceus':"Lion's Mane"} mushrooms
{'Fistulina hepatica': 'Beefsteak', 'Laetiporus sulphureus': 'Chicken-of-the-Woods', 'Flammulina velutipes': 'Enoki', 'Hericium erinaceus': "Lion's Mane"}

Exercise 15.2

Add the following items to mushrooms:
Pleurotus pulmonarius: Summer oyster
Pleurotus euosmos: Tarragon

mushrooms['Pleurotus pulmonarius'] = 'Summer oyster' mushrooms['Pleurotus euosmos'] = 'Tarragon' mushrooms
{'Fistulina hepatica': 'Beefsteak', 'Laetiporus sulphureus': 'Chicken-of-the-Woods', 'Flammulina velutipes': 'Enoki', 'Hericium erinaceus': "Lion's Mane", 'Pleurotus pulmonarius': 'Summer oyster', 'Pleurotus euosmos': 'Tarragon'}

Exercise 15.3

Print the common name for Laetiporus sulphureus.

mushrooms['Laetiporus sulphureus']
'Chicken-of-the-Woods'

Exercise 15.4

Replace the common name for Laetiporus sulphureus with Sulphur Shelf (this is another common name for this species which forms striking golden-yellow shelf-like fungal structures on tree trunks and branches.)

mushrooms['Laetiporus sulphureus'] = 'Sulphur Shelf' mushrooms
{'Fistulina hepatica': 'Beefsteak', 'Laetiporus sulphureus': 'Sulphur Shelf', 'Flammulina velutipes': 'Enoki', 'Hericium erinaceus': "Lion's Mane", 'Pleurotus pulmonarius': 'Summer oyster', 'Pleurotus euosmos': 'Tarragon'}

Exercise 15.5

Test if the species Pholiota nameko is in mushrooms.

if 'Pholiota nameko' in mushrooms: print('yes') else: print('no')
no

Exercise 15.6

Create an empty dictionary called books.

books = {}

Exercise 15.7

Add the following two books to your dictionary books:

Book titleAuthour
The chimpanzees of GombeJane Goodall
The blind watchmakerRichard Dawkins
books['The chimpanzees of Gombe'] = 'Jane Goodall' books['The blind watchmaker'] = 'Richard Dawkins'
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-14-79fa85f20bef> in <module> 2 books['The blind watchmaker'] = 'Richard Dawkins' 3 ----> 4 print(books[1]) KeyError: 1