I have stared at this line of code for far too long and I do not understand the exception at all. The line of code is
if '_' in part_word:
and the exception is
Exception has occurred: KeyError
'__________n'
File "C:\Users\timregan\source\pythonlessons\Hangman-Game\Hangman_learn.py", line 50, in play_and_learn
if '_' in part_word:
File "C:\Users\timregan\source\pythonlessons\Hangman-Game\Hangman_learn.py", line 66, in main
play_and_learn()
File "C:\Users\timregan\source\pythonlessons\Hangman-Game\Hangman_learn.py", line 71, in <module>
main()
(N.B. In comments people have asked for more of the code. It is not clear to me which fragment(s) are relevant, so the two Python files are available here, and the problem line is line 50.)
At the point the exception is thrown part_word is '__________n'. Even stranger is this: a watch in the debugging pane clearly shows that '_' in part_word evaluates to True.
The code looks correct—'_' in part_word is the correct way to test if the string part_word contains the string '_'. I can see that it evaluates correctly to True in the debugging pane. Any yet it throws a KeyError in the main code. Why? How do I diagnose what is going wrong? How might I fix this?

Hangman_learn.pycfile, delete it. Also, restart Python.