Skip to content

🐛 [Bug]: Word-Building game crashes with IndexError when user enters empty input #1312

Description

@vipul674

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

  1. Run python word_building.py
  2. When prompted with "Your word: ", press Enter without typing anything
  3. 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

  • Bug is reproducible
  • Fix is minimal (3-4 lines of input validation)
  • No duplicate issues found in open or closed issues

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions