Skip to content

Commit 4285347

Browse files
committed
fix: validate empty input in Word-Building game to prevent IndexError
Closes steam-bell-92#1312 Add .strip() and empty-string check before accessing user_word[0]. Empty input was crashing with 'IndexError: string index out of range' on lines 41 and 56.
1 parent 793620e commit 4285347

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

games/Word-Building/word_building.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ def Main():
3737
# Game loop
3838
while True:
3939
# User input and validation
40-
user_word = input("Your word: ")
40+
user_word = input("Your word: ").strip()
41+
if not user_word:
42+
print("\nPlease enter a valid word!")
43+
continue
4144
if (bot_word is not None) and (user_word[0].lower() != bot_word[-1].lower()):
4245
print("\nInvalid word! Your word must start with the last letter of bot's word.")
4346
win = False

0 commit comments

Comments
 (0)