< Back

Post Lab 24

Post labs are to be done individually. Sharing files between students is not allowed. Doing so is an Academic Integrity violation, and will be treated as such.


Dictionaries will cause exceptions if you attempt to access a key that is not currently stored in the dictionary. Often times in our code, however, we might not know what keys are stored where in the dictionary. Demonstrate your knowledge of dictionaries by writing a function to alleviate these concerns.

Details

Write a function called default_get(a_dictionary, key). If key exists in a_dictionary, you should return the values stored for key. If key does not exist in a_dictionary, a \(-1\) should be returned. The function should not use the dictionary get method.

Make sure your program handles all necessary cases gracefully. What additional test cases should you check?

Sample Test Cases

Function Parameters Sample Output
{"a": 1, "b": 2}, "a" 1
{"a": 1, "b": 2}, "c" -1

Submission

Submissions for post labs are to be done via the inquire system. Go to http://inquire.roanoke.edu/ You should see a section for post labs. Submit your .py file to the appropriate post lab location.

Post labs are to be done individually. Sharing files between students is not allowed. Doing so is an Academic Integrity violation, and will be treated as such.