Library › Coding AI › High school students
Make range() practice problems that target off-by-one mistakes
Practice: Showing an example of what you want. About 5 minutes.
About this exercise
You keep missing range() questions. Make exactly 3 numbered practice problems, each 'How many times does this print? `for i in range(...): print(i)`', where problem 1 uses range(stop), problem 2 range(start, stop) and problem 3 a negative step. Then a line 'Answers' and 3 numbered answers that list the values of i and then the count, like '[2, 3, 4] - 3 times'. No code blocks, under 100 words.
Common mistakes when you ask AI for this
- Random topics. The AI mixes in while loops and break, which you already know. Try: Say: "Only range() problems: one with one number, one with start and stop, one with a negative step."
- Different question styles. The AI writes 'write a loop that...' problems that don't match the test. Try: Show it: "How many times does this print? `for i in range(2, 5): print(i)`".
- Answers without the values. A bare number doesn't show you where you went off by one. Try: Ask: "List the values of i, then the count, like [2, 3, 4] - 3 times."
- Too many, or with code blocks. The AI writes 10 problems with code blocks and explanations. Try: Add: "Exactly 3 numbered problems, then a line 'Answers'. No code blocks."
What a strong prompt includes
- Sets the number of problems
- Shows the problem shape
- Covers the three forms
- Asks for worked answers
- Separates the answers
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)