WHY BRAIN BUSTERS
SERIES?
Dear Maharathi,
Are you ready to unlock the secrets of Computer Science and conquer
every challenge that comes your way? If you're looking for a one-stop
guide that will make your Class 12 Computer Science exam preparation
smooth, powerful, and rewarding, then this book is for you!
The Brain Buster Series is not just another textbook—it's your ultimate
companion for mastering the key concepts, boosting your problem-
solving skills, and acing your exam with confidence. We’ve crafted this
series to make sure that every student, whether you're a beginner or
already ahead of the curve, will find something valuable to learn and
grow from.
Here's why you can't afford to miss this book:
1. Comprehensive Coverage of the Syllabus
Every question in this series is meticulously designed to cover the entire
Class 12 Computer Science syllabus. From Python programming to SQL
and data structures, we’ve got you covered. No topic is left untouched,
ensuring that you're fully prepared to tackle any question that comes
your way.
2. Challenging Yet Rewarding
The Brain Buster Series is packed with output-based questions, logical
challenges, and coding exercises that will test your limits and sharpen
your skills. Each question is a brain teaser designed to stimulate your
thinking, enhance your coding abilities, and prepare you for the
toughest exam questions.
3. Instant Understanding with Solutions
After every set of questions, you’ll find detailed explanations that
break down complex problems into simple steps. This allows you to
understand the 'why' behind the answers—so you don’t just
memorize solutions, but genuinely grasp the concepts.
4. Real-World Relevance
We don’t just focus on exams—we focus on making you industry-
ready. Learn how these topics come to life in the real world, and
develop skills that will serve you not only in exams but also in your
future career.
5. A Fun & Interactive Learning Experience
The best part? We’ve made learning fun! With interactive exercises,
quizzes, and challenges, studying doesn’t have to be boring. Feel the
satisfaction of cracking a tough question and growing your
confidence as you move through the series. It’s not just about grades
—it’s about becoming a Computer Science master.
6. Your Path to Exam Success
We know Class 12 is a critical year, and exams can be stressful. But
with the Brain Buster Series, you’ll have a solid strategy to approach
each question with confidence. You’ll no longer feel overwhelmed;
instead, you'll feel ready—with practice that’s both effective and
engaging.
Why Should You Get This Book?
Because you deserve to succeed, Maharathi.
Because you deserve to have the confidence to walk into your exam
room, knowing you’ve got the skills to dominate.
Because this book is designed to make YOU the winner, and we
believe that with a little guidance and the right approach, you will be
unstoppable.
#maharathiMaterial
CLASS 12
COMPUTER SCIENCE
OUTPUT-BASED
QUESTIONS
WITH SOLUTIONS
Arithmetic and Logical
Operators Ques 6. Evaluate the output:
import randomfruits = ['Apple',
'Banana', 'Cherry']
Ques 1. What will be the output of for i in range(3):
the following code? print(fruits[random.
print(10 + 3 * 2 - 5 / 5) randrange(len(fruits))], end='-')
(a) 25.0 (a) Random fruit names separated
(b) 13.0 by -
(c) 14.0 (b) Error
(d) 15.0 (c) None
(d) Apple-Banana-Cherry
Ques 2. Evaluate the output:
a, b = 4, 8
String Manipulation
print(a & b, a | b, a ^ b)
(a) 0, 12, 12
Ques 7. Determine the output:
(b) 0, 12, 4
S = "ComputerScience"
(c) 0, 12, 8
print(S[:5] + S[-5:])
(d) Error
(a) Compuience
(b) Compute
Ques 3. Determine the output:
(c) Computence
print(15 > 10 or 5 < 3 and 8 >= 8)
(d) Error
(a) True Ques 8. What is displayed by the
(b) False code?
(c) Error S = "HELLO PYTHON"
(d) None print([Link]()[1][::-1])
(a) NOTHYP
Ques 4. What is displayed by the (b) NOHTYP
following? (c) NOHTYP
print(4 << 2, 16 >> 3) (d) PYTHON
(a) 16, 2
(b) 8, 3 Ques 9. Predict the output:
(c) 16, 3 S = "MISSISSIPPI"
(d) 8, 2 print(S[0:4] + '-' + S[-4:])
(a) MISS-IPPI
Random Module and Looping (b) MISS-SIPPI
(c) MISS-PPI
Ques 5. Predict the output of this (d) None
code:
import random Lists
nums = [5, 10, 15, 20]
for i in range(2): Ques 10. What will this display?
print([Link](nums), lst = [100, 200, 300, 400]
end=" ") print(lst[1::2])
(a) 5 10 (a) [200, 400]
(b) Random output from nums (b) [100, 300]
twice (c) [200]
(c) Error (d) None
(d) 5 5
SOLUTIONS
QUESTION 1: FINAL OUTPUT:
print(10 + 3 * 2 - 5 / 5) The result is 15.0 (a floating-
point number). However,
Answer: (d) 15. Python’s default behavior when
printing a float without
CONCEPT INVOLVED: formatting retains the decimal
PEMDAS Rule: point.
Operator precedence in Python follows
this order: KEY POINTS TO REMEMBER:
Parentheses (P): Operations inside Order of Operations (PEMDAS):
parentheses are evaluated first. Always start with higher-
Exponents (E): Exponentiation (**) is precedence operators before
evaluated next. moving to addition or
Multiplication/Division (MD): Evaluated subtraction.
from left to right as they appear. Division results in a floating-
Addition/Subtraction (AS): Evaluated point value (/ always outputs a
last, from left to right. float in Python).
Subtraction involving a float (like
STEP-BY-STEP EVALUATION 16 - 1.0) retains the floating-
Expression: point representation.
10 + 3 * 2 - 5 / 5
No parentheses (P) or exponents (E), so
we move to Multiplication and Division.
Step 1 - Evaluate 3 * 2:
QUESTION 2:
3*2=6 a, b = 4, 8print(a & b, a | b, a ^ b)
Updated expression:
10 + 6 - 5 / 5 Answer: (a) 0, 12, 12
Step 2 - Evaluate 5 / 5:
5 / 5 = 1.0 CONCEPT INVOLVED:
Updated expression: Bitwise Operators:
10 + 6 - 1.0 & (AND): Compares each bit
Step 3 - Perform Addition (10 + 6): and returns 1 if both bits are 1,
10 + 6 = 16 otherwise 0.
Updated expression: | (OR): Compares each bit and
16 - 1.0 returns 1 if at least one bit is 1.
Step 4 - Perform Subtraction (16 - 1.0): ^ (XOR): Compares each bit
16 - 1.0 = 15.0 and returns 1 if the bits are
different, otherwise 0.
STEP-BY-STEP EVALUATION:
Binary Representation: not
and
a = 4 → 0100 (binary)
or (evaluated last).
b = 8 → 1000 (binary)
Logical expressions are short-
Step 1 - a & b (Bitwise AND): circuited, meaning Python
Perform bitwise AND: stops evaluating once the final
0100 & 1000 = 0000 result is determined.
Decimal equivalent: 0
Step 2 - a | b (Bitwise OR): STEP-BY-STEP EVALUATION:
Perform bitwise OR: Expression:
0100 | 1000 = 1100 15 > 10 or 5 < 3 and 8 >= 8
Decimal equivalent: 12 Step 1 - Evaluate Comparison
Operators:
Step 3 - a ^ b (Bitwise XOR):
15 > 10 → True
Perform bitwise XOR:
5 < 3 → False
0100 ^ 1000 = 1100 8 >= 8 → True
Decimal equivalent: 12 Updated expression:
True or False and True
FINAL OUTPUT: Step 2 - Apply and (evaluated
The output is 0, 12, 12. before or):
False and True → False
KEY POINTS TO REMEMBER: Updated expression:
Bitwise AND (&): Returns 1 if both bits True or False
Step 3 - Apply or:
are 1.
True or False → True
Bitwise OR (|): Returns 1 if at least one
bit is 1. FINAL OUTPUT:
Bitwise XOR (^): Returns 1 if the bits The result of the logical expression
are different. is True.
Binary operations are performed bit
by bit on the binary representations KEY POINTS TO REMEMBER:
of the numbers. Logical operators are evaluated in
the order: not > and > or.
Short-circuiting:
For or, if the first operand is
QUESTION 3:
True, the rest is not evaluated.
print(15 > 10 or 5 < 3 and 8 >= 8) For and, if the first operand is
False, the rest is not evaluated.
Answer: (a) True Comparison operators (<, >, >=, etc.)
are evaluated first, before logical
CONCEPT INVOLVED: operators.
Logical Operators and Precedence:
Python evaluates logical
operators (or, and, not) in the
following order:
KEY POINTS TO REMEMBER:
QUESTION 4:
Left Shift (<<): Multiplies the
print(4 << 2, 16 >> 3)
number by 2^n (where n is the
number of shifts).
Answer: (a) 16, 2
Example: 4 << 2 = 4 * 2^2 = 16.
Right Shift (>>): Divides the number
CONCEPT INVOLVED:
by 2^n (integer division).
Bitwise Shift Operators:
Example: 16 >> 3 = 16 // 2^3 = 2.
Left Shift (<<): Shifts the bits of a
Binary representations are useful
number to the left, filling with
for visualizing bitwise operations.
zeros on the right. Each shift to
the left is equivalent to
multiplying the number by 2.
Right Shift (>>): Shifts the bits of QUESTION 5:
a number to the right, discarding import random
the rightmost bits. Each shift to nums = [5, 10, 15, 20]
the right is equivalent to dividing for i in range(2):
the number by 2 (integer print([Link](nums),
division). end=" ")
STEP-BY-STEP EVALUATION: Answer: (b) Random output from
Expression: nums twice
4 << 2 and 16 >> 3
Step 1 - Evaluate 4 << 2 (Left Shift): CONCEPT INVOLVED:
Binary representation of 4 is [Link]():
100. This function randomly selects
Shifting left by 2 adds two zeros an element from the given
to the right: sequence (nums in this case).
100 → 10000 Each call to
10000 in binary is 16 in decimal. [Link](nums) is
Step 2 - Evaluate 16 >> 3 (Right independent, meaning the
Shift): results can vary on every run.
Binary representation of 16 is Loops:
10000. The for loop executes twice
Shifting right by 3 removes three (range(2)), calling
rightmost bits: [Link](nums) in each
10000 → 10 iteration.
10 in binary is 2 in decimal.
STEP-BY-STEP EVALUATION:
FINAL OUTPUT: Expression:
The output is 16, 2. The list nums is [5, 10, 15, 20].
The loop iterates twice
(range(2)).
print(fruits[[Link](len(f
Step 1 - Iteration 1: ruits))], end='-')
The first iteration calls
[Link](nums) and Answer: (a) Random fruit names
selects a random value from [5, separated by -
10, 15, 20].
Possible outputs: 5, 10, 15, or CONCEPT INVOLVED:
20. [Link]():
Step 2 - Iteration 2: Generates a random integer
The second iteration calls between 0 (inclusive) and the
[Link](nums) again, given value (len(fruits) here,
independently selecting another which is 3) exclusive.
random value from [5, 10, 15, Each call to
20]. [Link](len(fruits))
Output: independently selects an index
Since [Link](nums) is from the range [0, 1, 2].
called twice, the output will for Loop:
consist of two randomly The loop iterates 3 times
selected values from the list. (range(3)), printing a randomly
Example: 15 10, 5 5, or any other chosen fruit from the list in each
combination. iteration.
String Formatting in print():
FINAL OUTPUT: The end='-' ensures all fruit
The output will be two random names are printed on the same
values from nums, separated by a line, separated by a -.
space.
STEP-BY-STEP EVALUATION:
KEY POINTS TO REMEMBER: Expression:
[Link](nums): The list fruits = ['Apple',
Returns a randomly selected 'Banana', 'Cherry'].
element from the list nums. The loop runs 3 times (range(3)).
Each call is independent and can Step 1 - First Iteration:
return the same or different [Link](len(fruits))
elements. generates a random index from
range(n): [0, 1, 2].
Creates a sequence of n Example: Randomly selects 0,
iterations. In this case, the loop corresponding to Apple.
runs twice (range(2)). Step 2 - Second Iteration:
[Link](len(fruits))
generates another random
QUESTION 6: index.
import random Example: Randomly selects 2,
fruits = ['Apple', 'Banana', 'Cherry'] corresponding to Cherry.
for i in range(3):
Step 3 - Third Iteration:
STEP-BY-STEP EVALUATION:
[Link](len(fruits))
Expression:
generates yet another random
S[:5] + S[-5:]
index.
Step 1 - Evaluate S[:5]:
Example: Randomly selects 1,
S = "ComputerScience"
corresponding to Banana.
S[:5] extracts the first 5
Output:
characters: "Compu".
The result could be something
Step 2 - Evaluate S[-5:]:
like Apple-Cherry-Banana- or
S[-5:] extracts the last 5
any other random combination
characters: "ience".
of fruits.
Step 3 - Concatenate the Results:
"Compu" + "ience" →
FINAL OUTPUT:
"Compuience"
Random fruit names separated by -.
Correct Answer: (a) Random fruit
FINAL OUTPUT:
names separated by -
Compuience
KEY POINTS TO REMEMBER:
KEY POINTS TO REMEMBER:
[Link](n):
Positive indices (S[:5]) start from the
Generates a random integer
beginning of the string.
from 0 to n-1.
Negative indices (S[-5:]) start from
Each call is independent, and
the end of the string.
indices may repeat.
String slicing is non-destructive and
Loop Iterations:
creates a new substring.
The for loop ensures the
operation is performed 3 times.
The end='-' argument in print() adds
a - after each fruit name. QUESTION 8:
S = "HELLO PYTHON"
print([Link]()[1][::-1])
QUESTION 7: Answer: (b) NOHTYP
S = "ComputerScience"
print(S[:5] + S[-5:]) CONCEPT INVOLVED:
split() Function: Splits a string into a
Answer: (a) Compuience list of words.
Default behavior splits by
CONCEPT INVOLVED: whitespace.
String Slicing: In this case, "HELLO PYTHON" is
S[:n]: Extracts the substring from split into ['HELLO', 'PYTHON'].
the start up to (but not String Reversal:
including) index n. [::-1] reverses the string
S[-n:]: Extracts the last n character by character.
characters of the string.
STEP-BY-STEP EVALUATION: STEP-BY-STEP EVALUATION:
Expression: Expression:
[Link]()[1][::-1] S[0:4] + '-' + S[-4:]
Step 1 - Apply split(): Step 1 - Extract S[0:4]:
"HELLO PYTHON".split() S = "MISSISSIPPI"
produces the list: S[0:4] extracts characters from
['HELLO', 'PYTHON']. index 0 to 3 (exclusive of 4):
Step 2 - Access the Second Word "MISS".
([1]): Step 2 - Extract S[-4:]:
[Link]()[1] retrieves the second S[-4:] extracts the last 4
word: characters of the string:
"PYTHON". "IPPI".
Step 3 - Reverse the Word ([::-1]): Step 3 - Concatenate with '-':
"PYTHON"[::-1] reverses the Combine the results:
characters: "MISS" + '-' + "IPPI" → "MISS-IPPI"
"NOHTYP".
FINAL OUTPUT:
FINAL OUTPUT: MISS-IPPI
NOHTYP
KEY POINTS TO REMEMBER:
KEY POINTS TO REMEMBER: String slicing:
String splitting: The split() function S[start:end] extracts characters
creates a list of substrings. starting at start and stopping
Indexing: [1] accesses the second before end.
word of the list. S[-n:] extracts the last n
Reversing: [::-1] reverses the characters.
characters in a string. Concatenation: Use + to join strings
with custom characters like '-'.
QUESTION 9:
S = "MISSISSIPPI" Question 10:
print(S[0:4] + '-' + S[-4:]) lst = [100, 200, 300, 400]
print(lst[1::2])
Answer: (a) MISS-IPPI
Answer: (a) [200, 400]
CONCEPT INVOLVED:
String Slicing: CONCEPT INVOLVED:
S[start:end] extracts characters List Slicing:
from start (inclusive) to end The slicing syntax
(exclusive). lst[start::step] extracts
S[-n:] extracts the last n elements from the list starting
characters of the string. at start, skipping step elements
between selections.
CONCEPT INVOLVED:
If the step is 2, every second
List Slicing with Negative Indices
element is selected from the
and Steps:
starting index.
lst[start:end:step] allows slicing
with negative indices and steps.
STEP-BY-STEP EVALUATION:
Negative step means slicing
Expression:
proceeds in reverse order.
lst[1::2]
Default values:
Step 1 - Starting Index (1):
If end is omitted with a
The slicing starts at index 1.
negative step, slicing stops
lst[1] = 200.
at the start of the list.
Step 2 - Step Size (2):
From the starting index (1), every
STEP-BY-STEP EVALUATION:
second element is selected:
Expression:
First selection: lst[1] = 200
lst[-1::-3]
Second selection: lst[3] =
Step 1 - Starting Index (-1):
400
The index -1 refers to the last
Result:
element of the list: 'D'.
The sliced list is [200, 400].
Step 2 - End Condition (None):
No specific end is provided, so
FINAL OUTPUT:
slicing continues until the start
[200, 400]
of the list.
Step 3 - Step Size (-3):
KEY POINTS TO REMEMBER:
Moving backwards in steps of 3:
List slicing syntax:
Start at lst[-1] = 'D'
lst[start::step]:
Step back 3 indices to lst[-4]
start: The index to begin
= 'A'
slicing.
Result:
step: The number of
The sliced list is ['D', 'A'].
elements to skip.
Default values for slicing:
FINAL OUTPUT:
start=0 if omitted.
['D', 'A']
step=1 if omitted.
In this example, 1::2 starts at index 1
Key Points to Remember:
and skips one element (step=2) in
Negative Step in Slicing:
each iteration.
A negative step reverses the
direction of slicing.
If end is not specified, slicing
continues to the start of the list.
QUESTION 11:
Negative Indices:
lst = ['A', 'B', 'C', 'D']
-1 refers to the last element of
print(lst[-1::-3])
the list.
Counting moves backwards: -1,
Answer: (b) ['D', 'A']
-2, -3, etc.