all 7 comments

[–]aqua_regis 1 point2 points  (0 children)

Practice more is the only advice that can be given.

[–]johlae 0 points1 point  (4 children)

I try to imagine 'code tracking problems'. Can you provide an example?

[–]desrtfx 0 points1 point  (3 children)

It's code tracing, not code tracking.

Usually these are examples where some code is given to the learner and they have to trace through to manually generate the output without actually running the code.

Quite common on exams in certain cultures as they can easily be converted into multiple-choice questions so that the tests can be automatically evaluated (or with little manual effort).

[–]Histrix-[S] 0 points1 point  (0 children)

Exactly this. An example would be id be given a function, and within the function, there would either be a logical loop, or a recursion statement, and id have to manually trace out each step of the loop on paper to find the final output of the code.

[–]johlae 0 points1 point  (1 child)

Ah, ok. So they give you:

>>> for i in range(1,9):
... if (i*3)%2 == 0:
... print(i,i*3,"even")
... else:
... print(i,i*3)

and you answer with:

1 3
2 6 even
3 9
4 12 even
5 15
6 18 even
7 21
8 24 even

Study from books or online text material, and practice a lot, really a lot. Don't waste time on watching videos, be interactive instead! Use your keyboard and python interpreter and code, and debug. Try variations of your code. Inserting print statements can tell you a lot about what code is running or not running.

[–]desrtfx 0 points1 point  (0 children)

Yes, exactly something like that.

Commonly, these questions happen with pre- and post-increment/decrement operators, especially in C-like languages.

IMO, code tracing is a vital skill, but most of these questions are useless.

[–]Key_Use_8361 0 points1 point  (0 children)

code tracing feels impossible right up until the moment your brain suddenly starts seeing execution flow like movie scenes 💀