Summary
The Word-Building game (games/Word-Building/word_building.py) crashes with an IndexError when the user enters an empty string (presses Enter without typing a word). The code attempts to access user_word[0] without validating that the input is non-empty.
Evidence
In games/Word-Building/word_building.py:40-41:
user_word = input("Your word: ")
if (bot_word is not None) and (user_word[0].lower() != bot_word[-1].lower()):
When user_word is an empty string "", user_word[0] raises:
IndexError: string index out of range
Additionally, on line 56:
if user_word not in data.words[user_word[0]]:
This also crashes with IndexError on empty input.
Affected Files
games/Word-Building/word_building.py (lines 41 and 56)
Reproduction Steps
- Run
python word_building.py
- When prompted with "Your word: ", press Enter without typing anything
- The game crashes with
IndexError: string index out of range
Expected Behavior
The game should display an error message like "Please enter a valid word!" and prompt for input again.
Actual Behavior
The game crashes with an unhandled IndexError traceback.
Impact
The game crashes on empty input, which is a common user mistake. This creates a poor user experience and makes the game fragile.
Suggested Fix
Add input validation after line 40:
user_word = input("Your word: ").strip()
if not user_word:
print("\nInvalid word! Please enter a non-empty word.")
continue
Candidate Validation
GSSoC 2026
This is a valid bug fix suitable for GSSoC 2026 contributors. The fix involves adding basic input validation, which is a good learning exercise.
Summary
The Word-Building game (
games/Word-Building/word_building.py) crashes with anIndexErrorwhen the user enters an empty string (presses Enter without typing a word). The code attempts to accessuser_word[0]without validating that the input is non-empty.Evidence
In
games/Word-Building/word_building.py:40-41:When
user_wordis an empty string"",user_word[0]raises:Additionally, on line 56:
This also crashes with
IndexErroron empty input.Affected Files
games/Word-Building/word_building.py(lines 41 and 56)Reproduction Steps
python word_building.pyIndexError: string index out of rangeExpected Behavior
The game should display an error message like "Please enter a valid word!" and prompt for input again.
Actual Behavior
The game crashes with an unhandled
IndexErrortraceback.Impact
The game crashes on empty input, which is a common user mistake. This creates a poor user experience and makes the game fragile.
Suggested Fix
Add input validation after line 40:
Candidate Validation
GSSoC 2026
This is a valid bug fix suitable for GSSoC 2026 contributors. The fix involves adding basic input validation, which is a good learning exercise.