Forward Deployed EngineeringFreshers and students

Output-prediction and pseudocode questions in campus tests, solved

PK
Pankit Kumar
Sr. Data Scientist at Parexel (a Goldman Sachs–backed company) · 27 September 2026 · 5 min read
In this article (6 sections)

Related programme: the FDE for Freshers course (6–7 months; EMI from ₹8,000/month · full fee shared on your counselling call). See also open Forward Deployed Engineer jobs in India, updated daily.

The short answer

Output-prediction and pseudocode questions show you a short program and ask what it prints. They test whether you can trace state — variable values, loop counters, what a function returns — without running the code. The reliable method is a trace table: one column per variable, one row per step, filled in with a pencil. The nine questions below cover the traps these sections return to most often: shared references, default arguments, integer division, loop bounds, slicing, swaps, bitwise operators, recursion and SQL NULLs.

Build a trace table before you answer

For any loop, write the variables across the top and update one row per iteration. It feels slow for the first week, then becomes faster than guessing — and it catches the one-off errors that cost most marks.

Stepiab
start–53
after i = 1185

That fragment is the start of question 6 below.

Python questions

Q1. What does this print?

text
x = [1, 2, 3]
y = x
y.append(4)
print(x)

Answer: `[1, 2, 3, 4]`. y = x does not copy the list; both names point to the same object. To copy, use y = x.copy() or y = list(x).

Q2. What do the two calls print?

text
def f(a, b=[]):
    b.append(a)
    return b

print(f(1))
print(f(2))

Answer: `[1]` then `[1, 2]`. The default list is created once, when the function is defined, and reused on every call. The usual fix is b=None and if b is None: b = [] inside the function.

Q3. What is printed?

text
print(7 // 2, -7 // 2, 7 % 3, -7 % 3)

Answer: `3 -4 1 2`. Python's // rounds down (towards negative infinity), so −3.5 becomes −4. The remainder takes the sign of the divisor, so −7 % 3 is 2 because −7 = 3 × (−3) + 2. C and Java give −3 and −1 for the negative cases, which is why tests like this question.

Q4. What is `count` after the loop?

text
count = 0
for i in range(1, 10, 3):
    count += i

Answer: 12. range(1, 10, 3) gives 1, 4, 7 — it stops before 10. 1 + 4 + 7 = 12.

Q5. What is printed?

text
s = "placement"
print(s[::-1][:3])

Answer: `tne`. s[::-1] reverses the string to "tnemecalp", and [:3] takes the first three characters.

Pseudocode questions

Pseudocode sections use a neutral syntax so that the question is about logic, not a language. Read = as assignment and assume integers unless told otherwise.

Q6. What is printed?

text
Integer a = 5, b = 3
for i = 1 to 3
    a = a + b
    b = a - b
end for
print a, b

Trace: after i = 1, a = 8 and b = 8 − 3 = 5. After i = 2, a = 13 and b = 13 − 5 = 8. After i = 3, a = 21 and b = 21 − 8 = 13. Answer: `21 13` — consecutive Fibonacci numbers, which is a hint worth noticing when a loop adds and subtracts like this.

Q7. What is printed?

text
Integer p = 12, q = 10
print (p AND q), (p OR q), (p XOR q)      // bitwise operators

12 is 1100 and 10 is 1010 in binary. AND keeps bits set in both: 1000 = 8. OR keeps bits set in either: 1110 = 14. XOR keeps bits set in exactly one: 0110 = 6. Answer: `8 14 6`.

Q8. What does `fun(7)` return?

text
Integer fun(Integer n)
    if n <= 1
        return 1
    return n + fun(n - 2)

fun(7) = 7 + fun(5) = 7 + 5 + fun(3) = 7 + 5 + 3 + fun(1) = 7 + 5 + 3 + 1. Answer: 16. Write each call on its own line and add from the bottom up.

A SQL output question

Tests for data roles sometimes include a query and ask for its result.

Q9. Table `marks` has four rows for column `score`: 70, NULL, 90, NULL. What does this return?

text
SELECT COUNT(*), COUNT(score), AVG(score) FROM marks;

Answer: `4, 2, 80.0`. COUNT(*) counts rows; COUNT(score) skips NULLs; AVG also skips NULLs, so it is (70 + 90) / 2, not 160 / 4.

Check all nine answers

After practising on paper, confirm your answers by running them. This script uses only the Python standard library, including the built-in sqlite3 module.

python
import sqlite3

x = [1, 2, 3]; y = x; y.append(4)
q1 = x

def f(a, b=[]):
    b.append(a)
    return b
q2 = (list(f(1)), list(f(2)))

q3 = (7 // 2, -7 // 2, 7 % 3, -7 % 3)

count = 0
for i in range(1, 10, 3):
    count += i
q4 = count

q5 = "placement"[::-1][:3]

a, b = 5, 3
for i in range(1, 4):
    a = a + b
    b = a - b
q6 = (a, b)

q7 = (12 & 10, 12 | 10, 12 ^ 10)

def fun(n):
    return 1 if n <= 1 else n + fun(n - 2)
q8 = fun(7)

con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE marks (score INTEGER)")
con.executemany("INSERT INTO marks VALUES (?)", [(70,), (None,), (90,), (None,)])
q9 = con.execute("SELECT COUNT(*), COUNT(score), AVG(score) FROM marks").fetchone()

for n, ans in enumerate([q1, q2, q3, q4, q5, q6, q7, q8, q9], start=1):
    print(f"Q{n}:", ans)

Expected output: [1, 2, 3, 4], ([1], [1, 2]), (3, -4, 1, 2), 12, tne, (21, 13), (8, 14, 6), 16 and (4, 2, 80.0).

How to practise this section

  • Write ten of your own questions a week from code you already know, predict the output, then run it. Writing questions teaches you where the traps are.
  • When you get one wrong, name the rule (reference vs copy, floor division, off-by-one), not just the answer.
  • Time yourself: most of these should take under a minute once you trace confidently.

These questions usually sit next to aptitude in the first round; see the 16-week placement plan for non-CS branches for where to fit them. If you enjoy tracing and debugging, that is the core daily skill of the engineering track in FDE for Freshers.

PK
Pankit Kumar
Lead Instructor, NeuraPath Academy

Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.

This article is part of our FDE for Freshers programme — 6–7 months. Build your engineering foundations, then take AI from discovery to delivery.

Explore FDE for Freshers
Counselling is free · no obligation

Not sure which programme fits?

Tell us your background and we will map it to the right entry point — including saying so when a cheaper programme is the better fit. A counsellor replies within one working day.