Library › Coding AI › College students
Trace a recursive function one call per line
Practice: Asking for a format you can use. About 5 minutes.
About this exercise
You're reviewing recursion for your CS 1 midterm and want to see every call of sum_digits(4096). Ask for exactly 5 numbered lines, one per call, each in the form 'sum_digits(4096) = 6 + sum_digits(409)', with the base case as line 5, then one last unnumbered line 'Total: N'. No code blocks and under 70 words in total.
Common mistakes when you ask AI for this
- Getting a paragraph. Asked to explain, the AI writes a general essay on recursion instead of the trace you need. Try: Say: "Exactly 5 numbered lines, one per call."
- Not showing the line shape. Without an example, the AI mixes words and math and skips the 0 digit. Try: Show it: "Format each like: 1. sum_digits(4096) = 6 + sum_digits(409)".
- Forgetting the base case. The AI may stop at sum_digits(4) and jump to the answer. Try: Add: "Line 5 is the base case sum_digits(0) = 0."
- No clean ending. The AI adds a recap or a code block with the function again. Try: Add: "Then one last line: Total: N. No code, nothing else."
What a strong prompt includes
- Sets the number of lines
- Shows the line shape
- Asks for the base case
- Asks for a total line
- Rules out code and extras
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)