I am trying to print out a message.
If a word in dictionary is not found then it should print out a message instead of giving an error.
What I thought is
if bool(bool(dictionary[word])) == True:
return dictionary[word]
else:
print 'wrong'
but it does not work when I write something that is not in dictionary instead it gives something like this
Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
translate_word('hous')
File "H:\IND104\final\Project 4 - Italian-Spanish Translator\trial 1.py", line 21, in translate_word
if bool(bool(dictionary[word])) == True:
KeyError: 'hous'
So how can I print out an error message thanks.
One way to achieve what you want is a
try/exceptblock: