How can I fix a KeyError in a python dictionary?
I was asked to create a dictionary and create a function number_dictionary(text, n). I'm able to return True or False if the text matches the n, but there's a KeyError when I put something that's not in the dictionary when it is supposed to return False.
I've put the two conditions together (when it does not match and not in the dictionary), but then it returns everything as False.
def number_dictionary(text,n):
numbers={'two': '2', 'three': '3', 'four': '4'}
if n != numbers[text] or n or text not in numbers:
return(False)
else:
return(True)