CJCoding With Joseph
15free / daySign inCreate account

Down Then Back Up

Write bounce(n: int) -> None that prints n, n - 1, down to 1 and then 1, 2, back up to n, one number per line, using a single recursive function: when n is 0 print nothing and return; otherwise print n, call the function with n - 1, and print n again after that call returns. The first print of each call happens on the way down and the second on the way back up as the calls finish. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one integer n, no prompt, which the tests read and pass to your function.

Expected Output:

3
2
1
1
2
3

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
Recursion
📥 Auto-Input:
3\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.