You asked an AI to build a simple "Number Guessing Game" using Streamlit. It wrote the code, ran away, and now the game is unplayable.
- You can't win.
- The hints lie to you.
- The secret number seems to have commitment issues.
- Install dependencies:
pip install -r requirements.txt - Run the broken app:
python -m streamlit run app.py
- Play the game. Open the "Developer Debug Info" tab in the app to see the secret number. Try to win.
- Find the State Bug. Why does the secret number change every time you click "Submit"? Ask ChatGPT: "How do I keep a variable from resetting in Streamlit when I click a button?"
- Fix the Logic. The hints ("Higher/Lower") are wrong. Fix them.
- Refactor & Test. - Move the logic into
logic_utils.py.- Run
pytestin your terminal. - Keep fixing until all tests pass!
- Run
Glitchy Guesser is a number guessing game built with Streamlit. The player selects a difficulty (Easy, Normal, or Hard), which sets the secret number's range and the number of allowed attempts. Each guess receives a hint — "Go HIGHER!" or "Go LOWER!" — to guide the player toward the secret number. The goal is to guess correctly before running out of attempts, with a score that decreases the more guesses it takes.
| # | Bug | Location |
|---|---|---|
| 1 | Hints were backwards — "Go HIGHER!" shown when guess was too high | check_guess in app.py |
| 2 | New Game button did nothing after a win or loss | New game handler in app.py |
| 3 | Submit button required two clicks to register | st.text_input + st.button in app.py |
| 4 | Attempts left counter started at 7 instead of 8 on Normal | Session state init in app.py |
| 5 | Normal and Hard difficulty ranges were swapped | get_range_for_difficulty in app.py |
| 6 | New Game always picked a secret from 1–100 regardless of difficulty | New game handler in app.py |
| 7 | Switching difficulty didn't reset the game state | Session state management in app.py |
- Swapped hint messages in
check_guess— paired "Go LOWER!" withguess > secretand "Go HIGHER!" withguess < secret. - Added
st.session_state.status = "playing"(and history reset) to the New Game handler so the game unblocks after a win or loss. - Wrapped text input and submit button in
st.formso both are submitted atomically in a single rerun, eliminating the double-click issue. - Changed
st.session_state.attemptsinit from1to0so the attempts left display is accurate from the start. - Swapped Normal and Hard return values in
get_range_for_difficulty— Normal is now 1–50, Hard is 1–100. - Replaced hardcoded
random.randint(1, 100)in the New Game handler withrandom.randint(low, high)to respect the selected difficulty. - Added difficulty change detection using
st.session_state.difficulty— switching difficulty now fully resets the game state. - Refactored
check_guessintologic_utils.pyand added aconftest.pyat the project root so pytest can find the module. - Fixed existing pytest tests to unpack the
(outcome, message)tuple returned bycheck_guess, and added two new tests specifically targeting the swapped hint message bug.
- [If you choose to complete Challenge 4, insert a screenshot of your Enhanced Game UI here]
