Day 005 of the 100 Days of Python challenge is a terminal Number Guessing Game. Python chooses a secret number from 1 to 100, and the player keeps guessing until they find it or quit.
Project Overview
The secret is generated once at the start of the game:
secret_number = random.randint(1, 100)
A while True loop keeps the game running. Each guess is checked for the special q command, converted to an integer inside a try block, and compared with the secret number. The program tells the player whether the guess is too low or too high.
The attempts counter increases only after a valid numeric guess. When the answer is correct, the game reports the number of attempts, prints a trophy, and breaks out of the loop.
Handling Invalid Input
A non-numeric response raises ValueError. The except block catches it and prints a helpful message instead of allowing the program to crash. This makes the game more forgiving for real users.
What This Project Teaches
Day 005 combines random number generation, infinite loops, break, exception handling, counters, and comparisons. It is also an example of a loop with several exit paths: a correct guess, a quit command, or continued play after a hint.
Running the Project
cd 100daysofpython/day005
python main.py
View the Day 005 source code on GitHub.
