Question: Write 3 functions in the starter code below such that: . add_to_dict[): takes a dictionary, a key, a value and adds the key value pair


Write 3 functions in the starter code below such that: . add_to_dict[): takes a dictionary, a key, a value and adds the key value pair to the dictionary. If key is already in dictionary then It displays the error message: "Error. Key already exists." Returns dictionary. remove_from_dict(): takes a dictionary and key and removes the key from the dictionary. Returns dictionary. If no such key is found in the dictionary then it prints: "No such key exists in the dictionary.". Hint: Use try-except find_key/dictt, key) takes dictionary and key and prints value corresponding to the key from the dictionary print("Value".value). If key is not found then prints: "Key not found." Hint Use try-except Example: Menu: add(a), remove(r).find(f): a Keyrich Value: 1 More (v)? y Menu: add(a), remove(r), find(n: a Key: alireza Value: 2 More (y)?n [l'alireza', 2), ('rich, 1)] Example 2: Menu: add(a), remove(r).find(f): a Key pranshu Value: 1 More (v)? y Menu: add(a),remove(r), find(r):r key to remove: enbody No such key exists in the dictionary More lv? n
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
