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.
item
is a key in the dictionary records
and print "<item> not found!"
if item
is not a key in the dictionary records
.Plan the solution with appropriate visualizations and pseudocode.
General Idea: Check if an item is in the dict, update if so, and otherwise print a customized error message.
1) Check if the key is in the dictionary
2) If so, set the dict at key -> new value
3) Otherwise, print the name of the item and "not found!"
"<item>"
.def update_or_warn(records, item, update_value):
if item in records:
records[item] = update_value
else:
print(item + " not found!")