TN Online Testசமச்சீர் கல்விப் பயிற்சி
12ஆம் வகுப்பு கணினி அறிவியல்

12th Computer Science Python Output Questions: Traced Line by Line

இந்தப் பாடத்தைப் பகிரவும்: Telegram

Output questions are where many students lose easy marks in Class 12 Computer Science. The code is always short, but one missed detail, such as a negative index or where a break sits, changes the answer. The fix is a habit: trace the code on paper, writing down the value of each variable after every line, before you look at the options.

Below are the patterns the book back questions use, each traced step by step.

1. Reversing a string with a slice

str1 = "TamilNadu"
print(str1[::-1])

A slice is written [start:stop:stride]. Leaving start and stop empty covers the whole string, and a stride of -1 walks backwards. Reading T-a-m-i-l-N-a-d-u from the end gives udaNlimaT. The capital N stays capital, and that detail is exactly what the wrong options change.

Two related facts: str1[0:5] gives Tamil, because the stop index is not included, and str1[-1] gives the last character, u.

2. Trying to change a string

str1 = "Chennai Schools"
str1[7] = "-"

Strings are immutable. You cannot assign to a single character, so this raises a TypeError. If you wanted a changed string, you would have to build a new one.

3. A while loop with break

i = 1
while True:
    if i % 3 == 0:
        break
    print(i, end=' ')
    i += 1
Passii % 3 == 0?Action
11Noprints 1, i becomes 2
22Noprints 2, i becomes 3
33Yesbreak, nothing printed

Output: 1 2. The check happens before the print, so 3 is never printed.

4. A while loop that runs once

T = 1
while T:
    print(True)
    break

Any non-zero number counts as true, so the loop starts. It prints True, then break ends the loop immediately. The output is a single line.

5. Negative indexing in a list

list1 = [2, 4, 6, 8, 10]
print(list1[-2])

Negative indexes count from the end: -1 is 10 and -2 is 8. For the same list, len(list1) is 5.

6. Changing and appending list elements

List = [10, 20, 30, 40, 50]
List[2] = 35      # [10, 20, 35, 40, 50]
List.append(32)   # [10, 20, 35, 40, 50, 32]

Lists are mutable. Index 2 is the third element, so 30 is replaced by 35. append() adds one element at the end; extend() would add several.

7. A list comprehension

S = [x**2 for x in range(5)]
print(S)

range(5) gives 0, 1, 2, 3 and 4. It stops before 5. Squaring each gives [0, 1, 4, 9, 16]. The common mistake is to include 25.

8. Set operations

setA = {3, 6, 9}
setB = {1, 3, 9}
print(setA | setB)
ExpressionOperationResult
setA | setBUnion{1, 3, 6, 9}
setA & setBIntersection{3, 9}
setA - setBDifference{6}
setA ^ setBSymmetric difference{1, 6}

A union keeps each value once, so duplicates disappear. Sets are unordered, so don't rely on the order in which elements are displayed.

9. A constructor that prints

class Student:
    def __init__(self, name):
        self.name = name
        print(self.name)

S = Student("Tamil")

Creating the object calls __init__() automatically, which stores the name and prints it. Output: Tamil. No separate method call is needed.

10. Skipping a row in a CSV file

import csv
d = csv.reader(open('city.csv'))
next(d)
for row in d:
    print(row)

If city.csv contains the lines chennai,mylapore and mumbai,andheri, next(d) consumes the first row, so the loop prints only ['mumbai', 'andheri']. Each row comes back as a list of strings.

A method for any new output question

  1. Write every variable as a column heading.
  2. Go line by line and update the values. For loops, add a row for every pass.
  3. Mark exactly when output happens, and whether end=' ' keeps it on one line.
  4. Check boundaries: where slices and ranges stop, negative indexes, and whether break comes before or after the print.

Practise with the solved sets for Control Structures, Strings and String Manipulation, Lists, Tuples, Sets and Dictionary and Python Classes and Objects, then take the timed tests on the Class 12 Computer Science section.

இந்தப் பாடத்தைப் பகிரவும்: Telegram

Related posts

12ஆம் வகுப்பு கணினி அறிவியல்

12th Computer Science Important 1 Mark Questions Chapter Wise

What the one-mark questions in 12th Computer Science test, chapter by chapter: programming concepts, Python rules, datab...

15 Sep 2026 · 4 min read
12ஆம் வகுப்பு கணினி அறிவியல்

Samacheer Kalvi 12th Computer Science Book Back Answers: All 16 Chapters

Book back MCQ answers for all 16 chapters of Samacheer Kalvi 12th Computer Science, with explanations, plus how to handl...

15 Sep 2026 · 3 min read
12ஆம் வகுப்பு பொருளியல்

12th Economics: Economists, Institutions and Important Dates in One List

Who said what, which institution does what, and which year matters: the recall facts behind many 12th Economics one-mark...

15 Sep 2026 · 3 min read