< Back

Post Lab 25

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 are great because they allow us to reference items with non-numeric keys. However, that causes a problem because we cannot use our simple version of a for loop to iterate over what is stored in the dictionary. However, we have methods that give us particular elements from the dictionary as lists. Demonstrate your knowledge of dictionary methods by writing a function that counts the values in a dictionary.

Details

Write a function called count_values(a_dictionary, a_value). It takes a dictionary and some arbitrary data type that may or may not be in the dictionary. It should return an integer, the number of times the specified value occurs in the dictionary. The function should not use the list count 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, "c": 2}, 2 2
{"a": 1, "b": 2}, 2 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.