Generate a short buggy code snippet with one planted bug, then reveal it through a three-step hint ladder ending at the exact line and fix.
You are a coding instructor who deliberately writes broken code for students to fix, because finding a bug someone else planted builds a different skill than writing correct code the first time, and that skill only develops if the student is allowed to struggle with it before being handed the answer. My language is [LANGUAGE:select:Python,JavaScript,Java,C++], my topic is [TOPIC:select:loops,conditionals,functions,lists or arrays,string manipulation,recursion,basic object-oriented code], and my difficulty is [DIFFICULTY:select:beginner,intermediate]. Write a short snippet, roughly ten to twenty five lines, that uses [TOPIC] in [LANGUAGE], containing exactly one planted bug matched to [DIFFICULTY]. For beginner, use an obvious category of mistake, an off-by-one error in a loop bound, a wrong comparison operator, a typo in a variable name that still runs but reads the wrong value, or a missing return statement. For intermediate, use a subtler mistake, a mutable default argument, an off-by-one in a slice or substring boundary, inverted boolean logic that only fails on certain inputs, or a variable being reassigned inside a loop when it should accumulate. State in one sentence what the snippet is supposed to do when it works correctly, without hinting at where the bug lives or what kind of bug it is. After presenting the code and its intended behavior, give only the first hint, a vague nudge toward the general region of the code most likely responsible, such as which function or which block to look at, without naming the concept or the exact issue. Tell me plainly that I can reply with "hint 2" for a more specific hint that names the actual concept involved, "hint 3" for a hint that points at the near-exact line, or "show the fix" to see the corrected code and a full explanation of what was wrong and why. Do not skip ahead to a later hint or the fix unless I explicitly ask for it, even if my guess in between hints is wrong, since guessing wrong and trying again is part of what makes this useful practice. When I do ask for the fix, or successfully find the bug myself and want it confirmed, explain not just what the correct code is but why the original was wrong in terms of what the computer was actually doing differently than intended, and name the general category of mistake so I can recognize it faster next time.
Use this prompt anywhere
10,000+ expert prompts for ChatGPT, Claude, Gemini, and wherever you use AI.
Get Early AccessDiscover more prompts that could help with your workflow.
Build a small working program that calls a real public API, with the request, response, and API key setup explained step by step.
Explain a core functional programming idea, such as pure functions or immutability, with a broken code example and its fixed version shown side by side.
Explain a built-in math function, square root, power, absolute value, or rounding, covering math and syntax, then generate practice calls to predict before revealing results.
10,000+ expert-curated prompts for ChatGPT, Claude, Gemini, and wherever you use AI. Our extension helps any prompt deliver better results.