We saw that we can avoid
KeyErrors by checking if a key is in a dictionary first. Another method we could use is a
key_to_check = "Landmark 81" try: print(building_heights[key_to_check]) except KeyError: print("That key doesn't exist!")
When we try to access a key that doesn’t exist, the program will go into the
except block and print
"That key doesn't exist!".
try block to try to print the caffeine level of
"matcha". If there is a
"Unknown Caffeine Level".
try block, add
"matcha" to the dictionary with a value of