Practice Sequence in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick Recap

Executing a series of instructions one after another in a fixed, specific order. In sequential execution, each instruction must complete before the next one begins, and the order in which statements appear determines the order in which they run.

Do this, then that, then the next thingβ€”order matters and each step must finish before the next.

Showing a random 20 of 76 problems.

Example 1

medium
Trace: x=4x=4; y=xβˆ—xy=x*x; x=1x=1; print yy. What prints?

Example 2

medium
Trace: SET x = 6. SET y = 4. SET x = x * y. SET y = x / y. OUTPUT x, y.

Example 3

easy
Trace this pseudocode: SET x = 2. SET y = x + 4. SET x = y * 2. OUTPUT x, y.

Example 4

hard
Trace: SET a = 3. SET b = a + 2. SET a = b * 2. SET b = a - b. OUTPUT a, b.

Example 5

easy
True or false: in pure sequence (no loops or ifs), each line runs exactly once.

Example 6

medium
Trace: L=[1,2]L=[1,2]; LL.append(3); LL.append(LL[0]); OUTPUT LL.

Example 7

medium
Two students wrote the same recipe steps in different orders. Student A: (1) preheat oven, (2) mix batter, (3) pour into pan, (4) bake. Student B: (1) mix batter, (2) pour into pan, (3) preheat oven, (4) bake. Which version is more efficient and why?

Example 8

challenge
Lines: (1) total=0, (2) total=total+price, (3) read price. A developer wrote them as 1,2,3. Why is total wrong, and what is the fix?

Example 9

challenge
Given 4 statements S1..S4S_1..S_4 where S3S_3 depends on S1S_1 and S4S_4 depends on S2S_2, how many valid total orderings exist?

Example 10

medium
Trace this swap attempt: SET a = 7. SET b = 2. SET a = b. SET b = a. OUTPUT a, b. Why doesn't this swap?

Example 11

medium
Trace: x=10x=10; y=x/2y=x/2; x=xβˆ’yx=x-y; OUTPUT xx.

Example 12

hard
A statement using zz appears at line 3; zz is assigned at line 7. Will the program work as written? Why or why not?

Example 13

medium
A recipe lists: (1) bake 30 min, (2) preheat oven, (3) mix batter. Why is order (2),(3),(1) correct rather than (1),(2),(3)?

Example 14

medium
Trace: count=0count=0; count=count+1count=count+1; count=countβˆ—2count=count*2; count=count+1count=count+1; OUTPUT countcount.

Example 15

easy
Which runs first in 'print A; print B; print C'?

Example 16

easy
Trace: ss = 'ab'; ss = ss + 'c'; ss = ss + 'd'. Final ss?

Example 17

medium
Using a temporary variable, write a correct swap of a and b assuming SET a = 7, SET b = 2 at the start. Then give the output of (a, b).

Example 18

medium
Trace: SET x = 4. SET y = x + 2. SET z = y * x. SET x = z - y. OUTPUT x.

Example 19

easy
In a sequence of 3 statements with no loops or ifs, how many times does the middle statement run?

Example 20

medium
Trace: x=5x=5; y=10y=10; swap (no temp): x=x+yx=x+y; y=xβˆ’yy=x-y; x=xβˆ’yx=x-y. Final x,yx,y?