Skip to content

🐛 [Bug]: Game crashes with ValueError on non-integer input in Number Guessing Game #756

@jbkun069

Description

@jbkun069

📝 Description
In the Number Guessing Game, if a user accidentally types a letter, special character, or string (e.g., "five") instead of a numerical digit, the game completely crashes instead of gracefully handling the error. The script needs a try-except block to validate user input and prevent the application from breaking.

🔄 Steps to Reproduce
Navigate to the games/Number-Guessing-Game/ directory.

Run the script using python Number-Guessing-Game.py.

When prompted to enter your guess, type a non-numeric string like abc or leave it blank and press Enter.

See the terminal crash with a Traceback.

🎯 Expected Behavior
The game should catch the invalid input and display a friendly warning message (e.g., "⚠️ Invalid input! Please enter a valid whole number."). It should then prompt the user to try again without crashing the program or consuming one of their remaining guesses.

❌ Actual Behavior / Error Logs
The program immediately terminates with the following standard Python error:

Plaintext
ValueError: invalid literal for int() with base 10: 'abc'
💻 Environment
OS: Windows 11 / macOS Sonoma

Python Version: 3.12.x

File Name: games/Number-Guessing-Game/Number-Guessing-Game.py

[x] I am a registered GSSoC 2026 contributor.

[x] I want to be assigned to fix this issue.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions