Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 2- An Introduction to Dictionaries Quick Reference D= {}creates an empty dictionary D={keyl:valuel. ---} creates a non-empty dictionary D[key] returns the value that mapped

image text in transcribed

Exercise 2- An Introduction to Dictionaries Quick Reference D= {}creates an empty dictionary D={keyl:valuel. ---} creates a non-empty dictionary D[key] returns the value that mapped to by key- (What if there's no such key?) D[key] =newvalue maps newvalue to key. Overwrites any previous value. Remember -newvalue can be any valid Python data structure. del D[key] deletes the mapping with that key from D. len(D) returns the number of entries (mappings) in D. x in D. x not in D checks whether the key x is in the dictionary D. D.keys0 -returns a list of all the keys in the dictionary. D.values() -returns a list of all the values in the dictionary. For this exercise, write a dictionary that catalogs the classes you took last term, the keys should be the class number, and the values should be the title of the class. Then, write a function "add_class" that takes 3 arguments, these are class number, and class title and the dictionary you have built. This "add_class function adds new classes to your dictionary. Use this function to add the classes you're taking next term to the dictionary Finally, write a function print_classes that print classes. It takes two arguments, these are the course number (4155) and the dictionary you've built and prints out the class number and class title. Example output: >>>print_classes('4155", my_classes) 4155 - Introduction to Python >>>print_classes ( 4806, my_classes) 4806 -Ethical Hacking >>>print_classes(-9999, my_classes) No course 9999 was taken For this exercise, we suggest using strings everywhere. Be sure to test with Course numbers that you both did and did not take

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

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

Students also viewed these Databases questions