forked from codepath/compsci_guides
-
Notifications
You must be signed in to change notification settings - Fork 0
Print Pair
Jessica Sang edited this page Sep 14, 2024
·
1 revision
Unit 2 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Print a requested dictionary entry, or an error if not found.
1) Check if the target is in the dictionary keys
2) If so:
a) print the target as the key
b) use the key to get the value and print the value
3) If not, print an error messagedef print_pair(dictionary, target):
if target in dictionary:
print("Key: " + target)
print("Value: " + dictionary[target])
else:
print("That pair does not exist!")