In this article, we are going to discuss 20 High-Order Thinking Skills (HOTS) Questions with Solutions – Class 12 Computer Science (Python). Let us begin !
Topics Covered
20 HOTS Questions with Solutions – Class 12 Computer Science Python (CBSE 2026)
These questions are taken from the below given topics:
- Tokens
- Variable Assignments
- Expressions
- Flow of control
- Strings
- Lists
- Tuples
- Dictioanries
These topics are from the chapter Python revision tour. So let us begin:
[1] Identify the tokens from the given code:
if age >= 18 and age <= 60:
print("Eligible for vote")
else:
print("Not Eligible not eligible for vote")
Ans.:
1. Keywords: if, and, else, print
2. Identifiers: age
3. Operators: >=, <=, = 4. Literals: 18, 60, "Eligible", "Not Eligible" [/showhide]
[2] What will be the output of the following code:
x = y = z = 100
x += 10
y -= 5
z *= 2
print(x, y, z)
Ans.:
Output: 110 95 200
Explanation:
x, y, z are assigned the same value 100 using multiple assignment.
x += 10 → 100 + 10 = 110
y -= 5 → 100 – 5 = 95
z *= 2 → 100 × 2 = 200
[3] Predict the output:
a = 5
b = 3.14
c = "Hello"
d = True
print(type(a), type(b), type(c), type(d))
Ans.:
Explanation:
a → integer (int)
b → floating-point (float)
c → string (str)
d → boolean (bool)
[4] What will be the result of the following expression? Explain the order of operations.
result = 10 + 2 * 5 / (3 - 1) ** 2
print(result)
Ans.:
Output: 10 + 2 * 5 / 4 → 10 + 10 / 4 → 10 + 2.5 = 12.5
Explanation:
According to PEMDAS:
Parentheses → (3 – 1) = 2
Exponent → 2 ** 2 = 4
Multiplication and Division (left to right) → 2 * 5 = 10, then 10 / 4 = 2.5
Addition → 10 + 2.5 = 12.5
[5] Identify the errors in the given program and rewrite the correct code and underline the corrections:
num = int("Enter a number: ")
if num > 0
print("Positive")
else if num < 0:
print("Negative")
else:
print(Zero)
Ans.:
num = int(input("Enter a number: ")) #input function is missing
if num > 0: #colon is mising
print("Positive")
elif num < 0: #elif not else if
print("Negative")
else:
print("Zero") #Zero should be enclosed in double quotation
[6] What will be the output of the following code:
a, b = 0, 1
for _ in range(4):
print(a, end=" ")
a, b = b, a + b
Ans.:
0 1 1 2
Iteration 1:
Print a → 0
Update: a = b → 1, b = a + b → 0 + 1 = 1
Iteration 2:
Print a → 1
Update: a = b → 1, b = a + b → 1 + 1 = 2
Iteration 3:
Print a → 1
Update: a = b → 2, b = a + b → 1 + 2 = 3
Iteration 4:
Print a → 2
Update: a = b → 3, b = a + b → 2 + 3 = 5
[7] What will be the output of given code:
a = b = c = 100
a += 10
b -= 5
c *= 2
print(a, b, c)
Ans.: 110 95 200
Explanation:
a = 100 + 10 = 110
b = 100 – 5 = 95
c = 100 * 2 = 200
[8] What will be the output for the following:
for Name in ['John', 'Garima','Seema','Karan']:
print(Name)
if Name[-1]=='a':
break
else:
print('Completed!')
print('Weldone!')
Ans.:
John
Garima
Weldone!
Explanation:
Explanation:
Iteration 1:
Name = ‘John’ → Prints John.
Name[-1] → Last character is ‘n’ → Condition Name[-1] == ‘a’ → False → No break.
Iteration 2:
Name = ‘Garima’ → Prints Garima.
Name[-1] → Last character is ‘a’ → Condition Name[-1] == ‘a’ → True → The loop breaks.
else block:
Since the loop breaks, the else block is skipped.
After the loop:
print(‘Weldone!’) → Executes, displaying Weldone!.
[9] Name the function/method required to
(i) check if a string contains only alphabets
(ii) reutrn the position of specified character
Ans.
(i) isalpha()
(ii) find(), index()
[10] Out of the following, find those identifiers, which cannot be used as identifiers in a Python program:
Total*Tax, While, class, switch, 3rdRow, finally, Column31, _Total
Ans.
Total*Tax – No special characters allows in identifier name
class- Keyword
3rdRow – Identifier must starts with alphabet
finally – Keyword
[11] Name the Python Library modules which need to be imported to invoke the following functions.
(i) mean()
(ii) randint()
Ans.
mean() → statistics module
randint() → random module
[12] Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code.
for Name in <'Rachana','Komal','Kapil','Paresh'>:
IF Name[0]='K':
print(name)
Ans.:
for Name in ['Rachana', 'Komal', 'Kapil', 'Paresh']:#Changed to a valid list form
if Name[0] == 'K': #Changed 'IF' to 'if'
#Used == instead of '='
print(name) #Name instead of Name
[13] Find and write the output of the following Python code:
v = [11, 20, 33, 40]
for i in v:
for j in range(1, i % 5):
print(j, "*", end="")
Ans.:
1*2*
Iteration and Output Analysis:
For i = 11:
i % 5 = 1
range(1, 1) → Empty range, no inner loop execution.
Output: (empty line)
For i = 20:
i % 5 = 0
range(1, 0) → Empty range, no inner loop execution.
Output: (empty line)
For i = 33:
i % 5 = 3
range(1, 3) → Iterates over 1 and 2.
Output:
1*2*
For i = 40:
i % 5 = 0
range(1, 0) → Empty range, no inner loop execution.
Output: (empty line)
[14] Which of the following can be used as valid variable identifier(s) in Python ?
(i) elif
(ii) BREAK
(iii) in
(iv) _Total
Ans.:
(ii) BREAK – Python is case-sensitive, so BREAK (in uppercase) is not the same as the keyword break (lowercase). Therefore, BREAK can be used as a variable name.
(iv) _Total is a valid identifier. Python allows variable names to start with an underscore (_), although such names are often used to indicate private variables by convention.
[15] Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code.
NUM1=1234
1=DAY1
for C in range[1,4]:
NUM1+C=NUM1
DAY1=DAY1+2
print(C)
print(NUM1:DAY1)
Ans.:
NUM1=1234
l=DAY1 #Replace l with 1
for C in range(1,4): #Replace square brackets with round brackets
NUM1=NUM1+C #Replace lvalue with rvalue
DAY1=DAY1+2
print(C)
print(NUM1,DAY1) #Use comma inplace of colon
[16] Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code.
Val = int(input("Value:"))
Adder = 0
for C in range(1,Val,3)
Adder=+C
if C%2=0:
Print(C*10)
else:
print(C+10)
print(Adder)
Ans.:
Val = int(input("Value:"))
Adder = 0
for C in range(1,Val,3): #Colon is missing
Adder+=C #The operator is incorrect =+ replaced with +=
if C%2==0: #Single equal to is given, required ==
print(C*10) #Print is given, replaced with print
else:
print(C+10)
print(Adder)
[17] Find and write the output of the following Python code :
Data = ["P",20,"R",10,"S",30]
Times = 0
Alpha = ""
Add = 0
for C in range(1,6,2):
Times = Times + C
Alpha = Alpha + Data[C-1]+"$"
Add = Add + Data[C]
print(Times,Add,Alpha)
Ans.:
Intitial Values:
Data = [“P”, 20, “R”, 10, “S”, 30]
Times = 0
Alpha = “”
Add = 0
C=1
Times = Times + C → 0 + 1 = 1
Alpha = Alpha + Data[1-1] + “$” → “” + “P” + “$” = “P$”
Add = Add + Data[1] → 0 + 20 = 20
Output – 1 20 P$
C=3
Times = Times + C → 1 + 3 = 4
Alpha = Alpha + Data[3-1] + “$” → “P$” + “R” + “$” = “P$R$”
Add = Add + Data[3] → 20 + 10 = 30
Output – 4 30 P$R$
C=5
Times = Times + C → 4 + 5 = 9
Alpha = Alpha + Data[5-1] + “$” → “P$R$” + “S” + “$” = “P$R$S$”
Add = Add + Data[5] → 30 + 30 = 60
Output – 9 60 P$R$S$
Final Output:
1 20 P$
4 30 P$R$
9 60 P$R$S$
[18] Which of the following are valid operators in Python :
(i) **
(ii) */
(iii) like
(iv) | |
(v) is
(vi) ^
(vii) between
(viii) in
Ans.:
Valid Operators are:
(i) ** (Exponent)
(v) is (Identity)
(vi) ^ (Bitwise)
(viii) in (Membership)
[19] Find and write the output of the following python code :
Text1 = "SSCE 2025"
Text2 = " "
I = 0
while I < len(Text1):
if Text1[I] >= "0" and Text1[I] <= "9":
Val = int(Text1[I])
Val = Val + 1
Text2 = Text2 + str(Val)
elif Text1[I] >= "A" and Text1[I] <= "Z":
if I + 1 < len(Text1):
Text2 = Text2 + Text1[I + 1]
else:
Text2 = Text2 + "*"
else:
Text2 = Text2 + "*"
I = I + 1
print(Text2)
Ans.:
Initial Values:
Text1 = “SSCE 2025”
Text2 = ” “
I = 0
I=0
Text1[0] = “S”
Condition: Text1[0] >= “A” and Text1[0] <= "Z" → True
Add Text1[1] (I + 1) → Text2 = " S"
I=1
Text1[1] = "S"
Condition: Text1[1] >= “A” and Text1[1] <= "Z" → True
Add Text1[2] → Text2 = " SC"
I=2
Text1[2] = "C"
Condition: Text1[2] >= “A” and Text1[2] <= "Z" → True
Add Text1[3] → Text2 = " SCE"
I=3
Text1[3] = "E"
Condition: Text1[3] >= “A” and Text1[3] <= "Z" → True
Add Text1[4] → Text2 = " SCE "
I=4
Text1[4] = " " (space)
Goes to else → Add * → Text2 = " SCE *"
I=5
Text1[5] = "2"
Condition: Text1[5] >= “0” and Text1[5] <= "9" → True
Convert to integer → int(2) = 2
Add 1 → 2 + 1 = 3
Add 3 to Text2 → Text2 = " SCE *3"
I=6
Text1[6] = "0"
Condition: Text1[6] >= “0” and Text1[6] <= "9" → True
Convert to integer → int(0) = 0
Add 1 → 0 + 1 = 1
Add 1 to Text2 → Text2 = " SCE *31"
I=7
Text1[7] = "2"
Condition: Text1[7] >= “0” and Text1[7] <= "9" → True
Convert to integer → int(2) = 2
Add 1 → 2 + 1 = 3
Add 3 to Text2 → Text2 = " SCE *313"
I=8
Text1[8] = "5"
Condition: Text1[8] >= “0” and Text1[8] <= "9" → True
Convert to integer → int(5) = 5
Add 1 → 5 + 1 = 6
Add 6 to Text2 → Text2 = " SCE *3136"
Final Output:
SCE *3136
[/showhide]
[20] Write the names of any four data types available in Python.
Ans.:
1. int → Represents integer values.
Example: x = 10
2. float → Represents decimal or floating-point numbers.
Example: y = 3.14
3. str → Represents a sequence of characters (string).
Example: name = “Python”
4. bool → Represents Boolean values (True or False).
Example: is_valid = True
[21] Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code.
250 = Number
WHILE Number<=1000:
if Number=>750:
print Number
Number=Number+100
else
print Number*2
Number=Number+50
[22] Find and write the output of the following python code :
Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+"*"
print(Msg3)
[23] Identify the valid keywords in Python from the following :
(i) Queue
(ii) False
(iii) in
(iv) Number
(v) global
(vi) method
(vii) import
(viii) List
[24] Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code.
W = raw_input('Enter a word')
If W <> 'HELLO':
print W + 2
else
print W * 2
[25] Evaluate the following Python expressions :
(a) 2 * 3 + 4 ** 2 5 // 2
(b) 6 < 12 and not (20 > 15) or (10 > 5)
[26] Rewrite the following code in Python after removing all syntax error(s) . Underline each correction done in the code.
Runs = ( 10, 5, 0, 2, 4, 3 )
for I in Runs:
if I=0:
print(Maiden Over)
else
print(Not Maiden)