Summary
The Word-Building game (games/Word-Building/word_building.py line 56) crashes with a KeyError when the user enters a word whose first letter is not a key in the data.words dictionary. The code accesses data.words[user_word[0]] without checking whether that key exists.
Evidence
In games/Word-Building/word_building.py:56:
if user_word not in data.words[user_word[0]]:
data.DataAdding(user_word)
If the user enters a word like "zebra" and the letter "z" is not a key in the data.words dictionary (loaded from words.bat), this line raises:
The data.words dictionary is loaded from a pickle file (words.bat) and may not contain entries for all 26 letters of the alphabet.
Note: This is distinct from issue #1204 which reports a similar KeyError in the DataAdding() function in data.py. This bug is in the Main() function in word_building.py.
Affected Files
games/Word-Building/word_building.py (line 56)
Reproduction Steps
- Run
python word_building.py
- Play through the first round (bot starts)
- Enter a word that starts with a letter not present in the
data.words dictionary
- The game crashes with
KeyError
Expected Behavior
The game should handle missing keys gracefully — either by adding the key to the dictionary or by displaying an error message and prompting for a different word.
Actual Behavior
The game crashes with an unhandled KeyError traceback.
Impact
The game crashes when users enter words with uncommon starting letters. This makes the game fragile and limits the vocabulary users can play with.
Suggested Fix
Use .get() with a default empty list, or check for key existence:
if user_word[0] not in data.words or user_word not in data.words[user_word[0]]:
data.DataAdding(user_word)
Or in data.pys DataAdding function, initialize missing keys:
def DataAdding(word):
# ...existing code...
if word[0] not in words:
words[word[0]] = []
# ...rest of code...
Candidate Validation
GSSoC 2026
This is a valid bug fix suitable for GSSoC 2026 contributors. The fix involves defensive programming with dictionary key checks, which is a fundamental Python skill.
Summary
The Word-Building game (
games/Word-Building/word_building.pyline 56) crashes with aKeyErrorwhen the user enters a word whose first letter is not a key in thedata.wordsdictionary. The code accessesdata.words[user_word[0]]without checking whether that key exists.Evidence
In
games/Word-Building/word_building.py:56:If the user enters a word like "zebra" and the letter
"z"is not a key in thedata.wordsdictionary (loaded fromwords.bat), this line raises:The
data.wordsdictionary is loaded from a pickle file (words.bat) and may not contain entries for all 26 letters of the alphabet.Note: This is distinct from issue #1204 which reports a similar KeyError in the
DataAdding()function indata.py. This bug is in theMain()function inword_building.py.Affected Files
games/Word-Building/word_building.py(line 56)Reproduction Steps
python word_building.pydata.wordsdictionaryKeyErrorExpected Behavior
The game should handle missing keys gracefully — either by adding the key to the dictionary or by displaying an error message and prompting for a different word.
Actual Behavior
The game crashes with an unhandled
KeyErrortraceback.Impact
The game crashes when users enter words with uncommon starting letters. This makes the game fragile and limits the vocabulary users can play with.
Suggested Fix
Use
.get()with a default empty list, or check for key existence:Or in
data.pysDataAddingfunction, initialize missing keys:Candidate Validation
GSSoC 2026
This is a valid bug fix suitable for GSSoC 2026 contributors. The fix involves defensive programming with dictionary key checks, which is a fundamental Python skill.