Class 9th DPS Python Extra Question.
1.
x = "5"
y = 10
print(x * y)
A. 50
B. 5555555555
C. 5 * 10
D. Error
✅ Answer: B
Explanation: String "5" repeated 10 times → "5555555555"
2.
a = True
b = False
print(a + b)
A. 1
B. True
C. 0
D. False
✅ Answer: A
Explanation: True = 1, False = 0, so 1 + 0 = 1.
3. print(type(3/2))
A. int
B. float
C. double
D. error
✅ Answer: B
Explanation: / always gives float in Python → 1.5 is float.
4. print(2 ** 3 ** 2)
A. 512
B. 64
C. 8
D. Error
✅ Answer: A
Explanation: ** is right-associative → 3**2 = 9 → 2**9 = 512.
5.
x = "Python"
print(x[::-1])
A. Python
B. nohtyP
C. Error
D. Pyt
✅ Answer: B
Explanation: [::-1] reverses the string.
6. print(5 // 2)
A. 2.5
B. 3
C. 2
D. Error
✅ Answer: C
Explanation: // = floor division → 5 // 2 = 2.
7. print("abc" * 3)
A. abcabcabc
B. abc3
C. abcabc
D. Error
✅ Answer: A
Explanation: "abc" repeated 3 times.
8. print(bool(0), bool(1), bool(2))
A. False True True
B. True True False
C. False False True
D. Error
✅ Answer: A
Explanation: 0 → False, non-zero → True.
9. print(len([1, [2, 3], 4]))
A. 3
B. 4
C. 5
D. Error
✅ Answer: A
Explanation: List has 3 elements (1, [2,3], 4).
10.
x = {1, 2, 2, 3}
print(len(x))
A. 4
B. 3
C. 2
D. Error
✅ Answer: B
Explanation: Sets remove duplicates → {1,2,3} → length = 3.
11.
d = {"a":1, "b":2}
print(d.get("c", 5))
A. 1
B. 2
C. 5
D. None
✅ Answer: C
Explanation: "c" not in dict, so default = 5.
12. print(10 > 5 and 5 < 3)
A. True
B. False
C. Error
D. None
✅ Answer: B
Explanation: 10>5 → True, 5<3 → False, so True and False = False.
13.
x = [1,2,3]
print(x[1:])
A. [1,2]
B. [2,3]
C. [1]
D. Error
✅ Answer: B
Explanation: Slice from index 1 → [2,3].
14. print("Hello" == "hello")
A. True
B. False
C. Error
D. None
✅ Answer: B
Explanation: Strings are case-sensitive.
15. print(sum([1,2,3,4]))
A. 10
B. 24
C. [1,2,3,4]
D. Error
✅ Answer: A
Explanation: 1+2+3+4=10.
16. print(7 % 3)
A. 1
B. 2
C. 3
D. Error
✅ Answer: A
Explanation: 7 mod 3 = 1.
17. print(type([1,2,3]))
A. list
B. tuple
C. dict
D. set
✅ Answer: A
18. print(3 * (1+2))
A. 9
B. 6
C. 3+2
D. Error
✅ Answer: A
Explanation: 3*(3)=9.
19. print("2" + "3")
A. 5
B. 23
C. Error
D. 2+3
✅ Answer: B
Explanation: String concatenation → "23".
20. print(list("ABC"))
A. ["A","B","C"]
B. ABC
C. ["ABC"]
D. Error
✅ Answer: A
21. print(min([5,3,9,1]))
A. 9
B. 1
C. 5
D. 3
✅ Answer: B
Explanation: Minimum value = 1.
1.
x = input("Enter: ")
print(x * 2)
Input: 5
A. 10
B. 55
C. Error
D. 25
✅ Answer: B
Explanation: input() returns string → "5" * 2 = "55".
2.
x = int(input("Enter: "))
print(x * 2)
Input: 5
A. 55
B. 10
C. Error
D. 25
✅ Answer: B
Explanation: With int(), 5*2 = 10.
3.
x = input("Enter: ")
print(type(x))
Input: 7
A. int
B. str
C. float
D. None
✅ Answer: B
Explanation: input() always gives str.
4.
x = float(input("Enter: "))
print(x + 2)
Input: 3
A. 5
B. 5.0
C. 32
D. Error
✅ Answer: B
Explanation: float(3) = 3.0 → 3.0+2=5.0.
5.
x = input("Enter: ")
print(x + "2")
Input: 3
A. 5
B. 32
C. 23
D. Error
✅ Answer: B
Explanation: String concat → "3" + "2" = "32".
6.
x = int(input("Enter: "))
print(x // 2)
Input: 9
A. 4.5
B. 4
C. 5
D. Error
✅ Answer: B
Explanation: Floor division → 9//2=4.
7.
x = input("Enter: ")
print(len(x))
Input: 12345
A. 12345
B. 5
C. 1
D. Error
✅ Answer: B
Explanation: String length = 5.
8.
x = input("Enter: ")
print(x == "10")
Input: 10
A. True
B. False
C. Error
D. None
✅ Answer: A
Explanation: Input string "10" matches "10".
9.
x = input("Enter: ")
print(int(x) + float(x))
Input: 4
A. 8.0
B. 44
C. 4.0
D. Error
✅ Answer: A
Explanation: int(4)=4, float(4)=4.0 → total=8.0.
10.
x = input("Enter: ")
print(x * 3)
Input: hi
A. hi3
B. hihihi
C. 3hi
D. Error
✅ Answer: B
Explanation: String repetition → "hi"*3 = "hihihi".
11.
x = int(input("Enter: "))
print(x % 2 == 0)
Input: 8
A. True
B. False
C. Error
D. None
✅ Answer: A
Explanation: 8 is even.
12.
x = input("Enter: ")
print(x.upper())
Input: python
A. python
B. PYTHON
C. Python
D. Error
✅ Answer: B
Explanation: .upper() → "PYTHON".
13.
x = input("Enter: ")
print(x[::-1])
Input: abc
A. abc
B. cba
C. bca
D. Error
✅ Answer: B
Explanation: [::-1] reverses string.
14.
x = input("Enter: ")
print(x.isdigit())
Input: 123
A. True
B. False
C. Error
D. None
✅ Answer: A
Explanation: "123".isdigit() → True.
15.
x = input("Enter: ")
print(x * 0)
Input: 7
A. 0
B. ""
C. None
D. Error
✅ Answer: B
Explanation: Any string * 0 = empty string "".
16.
x = int(input("Enter: "))
y = int(input("Enter: "))
print(x + y)
Input: 3 and 4
A. 34
B. 7
C. 12
D. Error
✅ Answer: B
Explanation: Both converted to int → 3+4=7.
17.
x = input("Enter: ")
print(x * 2 + "3")
Input: 5
A. 53
B. 553
C. 10
D. Error
✅ Answer: B
Explanation: "5"*2 → "55" + "3" → "553".
18.
x = input("Enter: ")
print(int(x) * int(x))
Input: 6
A. 36
B. 12
C. 66
D. Error
✅ Answer: A
Explanation: 6*6=36.
19.
x = input("Enter: ")
print(x.find("a"))
Input: cat
A. 0
B. 1
C. 2
D. -1
✅ Answer: B
Explanation: "a" found at index 1.
20.
x = input("Enter: ")
print(x.title())
Input: hello world
A. hello world
B. Hello World
C. Hello world
D. Error
✅ Answer: B
Explanation: .title() capitalizes each word.
21.
x = input("Enter: ")
print(x.isalpha())
Input: abc123
A. True
B. False
C. Error
D. None
✅ Answer: B
Explanation: isalpha() fails since digits are included.
1.
if x > 10
print("Greater")
A. IndentationError
B. Missing colon
C. NameError
D. No error
✅ Answer: B
Explanation: Colon missing after if x > 10.
2.
if True:
print("Hello")
A. No error
B. IndentationError
C. SyntaxError
D. NameError
✅ Answer: B
Explanation: Body of if must be indented.
3.
print("Hi)
A. SyntaxError
B. NameError
C. IndentationError
D. No error
✅ Answer: A
Explanation: String not closed properly.
4.
x = 5
print(y)
A. NameError
B. SyntaxError
C. IndentationError
D. No error
✅ Answer: A
Explanation: y not defined.
5.
x = "5" + 5
A. SyntaxError
B. TypeError
C. NameError
D. No error
✅ Answer: B
Explanation: Cannot concatenate string with int.
6.
for i in range(3)
print(i)
A. IndentationError
B. Missing colon
C. No error
D. NameError
✅ Answer: B
Explanation: Missing colon after range(3).
7.
def add(a, b)
return a+b
A. SyntaxError
B. Missing colon
C. NameError
D. IndentationError
✅ Answer: B
Explanation: Colon missing after function definition.
8.
def func():
print("Hi")
A. No error
B. IndentationError
C. SyntaxError
D. NameError
✅ Answer: B
Explanation: Function body must be indented.
9.
print("Hello", end = )
A. SyntaxError
B. TypeError
C. No error
D. IndentationError
✅ Answer: A
Explanation: end value missing → invalid syntax.
10.
for i in 5:
print(i)
A. SyntaxError
B. TypeError
C. No error
D. NameError
✅ Answer: B
Explanation: Integer is not iterable.
11.
x = [1,2,3]
print(x[5])
A. SyntaxError
B. IndexError
C. No error
D. NameError
✅ Answer: B
Explanation: List index out of range.
12.
print("Result is", 10/0)
A. SyntaxError
B. ZeroDivisionError
C. No error
D. ValueError
✅ Answer: B
Explanation: Division by zero is not allowed.
13.
x = (1,2,3)
x[0] = 5
A. TypeError
B. SyntaxError
C. No error
D. ValueError
✅ Answer: A
Explanation: Tuples are immutable.
14.
print(int("abc"))
A. SyntaxError
B. ValueError
C. No error
D. TypeError
✅ Answer: B
Explanation: Cannot convert non-numeric string to int.
15.
x = [1,2,3]
print(x[1:5])
A. IndexError
B. No error → [2, 3]
C. SyntaxError
D. ValueError
✅ Answer: B
Explanation: Python slicing is safe, result = [2,3].
16.
if 5 > 3:
print("Yes")
else
print("No")
A. IndentationError
B. Missing colon
C. SyntaxError
D. No error
✅ Answer: B
Explanation: Colon missing after else.
17.
print("Python"[-10])
A. No error
B. IndexError
C. SyntaxError
D. ValueError
✅ Answer: B
Explanation: Negative index beyond length causes IndexError.
18.
for i in range(3):
print(i)
A. IndentationError
B. SyntaxError
C. No error
D. NameError
✅ Answer: A
Explanation: Loop body must be indented.
19.
def f():
return
print("Hi")
A. Prints "Hi"
B. No error, but nothing prints
C. SyntaxError
D. IndentationError
✅ Answer: B
Explanation: return exits function before print.
20.
while True
break
A. Missing colon
B. IndentationError
C. No error
D. SyntaxError
✅ Answer: A
Explanation: Colon missing after while True.
21.
print(2 ** 1000)
A. OverflowError
B. SyntaxError
C. Prints a very large number
D. ValueError
✅ Answer: C
Explanation: Python handles big integers automatically.
1.
a = 5
if a == 5
print("Equal")
A. IndentationError
B. SyntaxError
C. Logical Error
D. No error
✅ Answer: A
Explanation: The print must be indented inside the if.
2.
x = 10
if x > 5:
print("Yes")
else
print("No")
A. Missing colon
B. IndentationError
C. SyntaxError
D. No error
✅ Answer: A
Explanation: else requires a colon.
3.
for i in range(3):
print(i)
A. IndentationError
B. SyntaxError
C. RuntimeError
D. No error
✅ Answer: A
Explanation: Loop body must be indented.
4.
x = "10"
y = 5
print(x + y)
A. No error
B. TypeError
C. SyntaxError
D. Logical Error
✅ Answer: B
Explanation: Cannot add string and integer.
5.
if True
print("Yes")
A. Missing colon
B. IndentationError
C. No error
D. Logical Error
✅ Answer: A
Explanation: Missing colon after condition.
6.
print("Hello"
A. SyntaxError
B. IndentationError
C. No error
D. Logical Error
✅ Answer: A
Explanation: Closing parenthesis is missing.
7.
x = 5 / 0
print(x)
A. ZeroDivisionError
B. SyntaxError
C. RuntimeError
D. Logical Error
✅ Answer: A
Explanation: Division by zero not allowed.
8.
x = [1, 2, 3]
print(x[5])
A. IndexError
B. SyntaxError
C. No error
D. Logical Error
✅ Answer: A
Explanation: Index 5 does not exist.
9.
def add(a, b)
return a + b
A. IndentationError
B. Missing colon
C. SyntaxError
D. No error
✅ Answer: B
Explanation: Colon missing after function definition.
10.
def func():
return
print("Hello")
A. No error but nothing prints
B. SyntaxError
C. IndentationError
D. Logical Error
✅ Answer: A
Explanation: return exits before print.
11.
x = "Python"
print(x[10])
A. IndexError
B. SyntaxError
C. No error
D. Logical Error
✅ Answer: A
Explanation: Index 10 is out of range.
12.
x = (1,2,3)
x[0] = 10
A. TypeError
B. SyntaxError
C. No error
D. Logical Error
✅ Answer: A
Explanation: Tuples are immutable.
13.
print("2" * "3")
A. TypeError
B. SyntaxError
C. No error
D. Logical Error
✅ Answer: A
Explanation: String cannot multiply with string.
14.
if 5 > 2:
print("Yes")
else:
print("No")
A. IndentationError
B. SyntaxError
C. No error
D. Logical Error
✅ Answer: C
Explanation: Valid code, prints "Yes".
15.
print(2 ** 1000)
A. OverflowError
B. SyntaxError
C. No error, prints a big number
D. Logical Error
✅ Answer: C
Explanation: Python supports big integers.
16.
print("Hello", end = )
A. SyntaxError
B. TypeError
C. No error
D. Logical Error
✅ Answer: A
Explanation: Value for end is missing.
17.
for i in "123":
print(i, end="")
A. 123
B. 1 2 3
C. No error, prints 123
D. IndentationError
✅ Answer: C
Explanation: Iterates over string, prints "123".
18.
a = 10
if a = 5:
print("Yes")
A. SyntaxError
B. IndentationError
C. Logical Error
D. No error
✅ Answer: A
Explanation: Assignment = not allowed in condition.
19.
print(int("abc"))
A. SyntaxError
B. ValueError
C. No error
D. Logical Error
✅ Answer: B
Explanation: Cannot convert non-numeric string.
20.
x = {"a":1, "b":2}
print(x["c"])
A. KeyError
B. SyntaxError
C. No error
D. Logical Error
✅ Answer: A
Explanation: "c" is not a valid key.
21.
if True:
print("Yes")
else:
print("No")
A. IndentationError
B. SyntaxError
C. No error
D. Logical Error
✅ Answer: A
Explanation: else misaligned → indentation error.
1.
x = 10
if x = 10:
print("Ten")
A. No error
B. SyntaxError – wrong operator
C. ValueError
D. TypeError
✅ Answer: B
Explanation: = is assignment, not allowed in condition. Must use ==.
2.
a = 5
if a == 5:
print("Equal")
A. IndentationError
B. SyntaxError
C. Logical Error
D. No error
✅ Answer: A
Explanation: print must be indented.
3.
if True
print("Yes")
A. No error
B. Missing colon
C. TypeError
D. IndentationError
✅ Answer: B
Explanation: Colon is missing after condition.
4.
for i in range(3):
print(i)
A. SyntaxError
B. IndentationError
C. No error
D. ValueError
✅ Answer: B
Explanation: Loop body not indented.
5.
x = "5" + 5
A. No error
B. TypeError
C. ValueError
D. SyntaxError
✅ Answer: B
Explanation: Cannot concatenate str and int.
6.
print("Hello"
A. SyntaxError
B. IndentationError
C. ValueError
D. No error
✅ Answer: A
Explanation: Missing closing parenthesis.
7.
y = 10 / 0
A. SyntaxError
B. ZeroDivisionError
C. ValueError
D. No error
✅ Answer: B
Explanation: Division by zero is not allowed.
8.
x = [1,2,3]
print(x[5])
A. IndexError
B. KeyError
C. SyntaxError
D. No error
✅ Answer: A
Explanation: Index out of range.
9.
def add(a, b)
return a + b
A. SyntaxError – missing colon
B. IndentationError
C. ValueError
D. No error
✅ Answer: A
Explanation: Function definition missing colon.
10.
def func():
return
print("Hello")
A. SyntaxError
B. No error – nothing prints
C. IndentationError
D. Logical Error
✅ Answer: B
Explanation: Code after return is ignored.
11.
x = "Python"
print(x[10])
A. IndexError
B. No error
C. SyntaxError
D. TypeError
✅ Answer: A
Explanation: Index 10 out of range.
12.
x = (1,2,3)
x[0] = 10
A. TypeError
B. SyntaxError
C. No error
D. Logical Error
✅ Answer: A
Explanation: Tuples are immutable.
13.
print(int("abc"))
A. TypeError
B. ValueError
C. SyntaxError
D. No error
✅ Answer: B
Explanation: Invalid literal for int.
14.
if 5 > 2:
print("Yes")
else:
print("No")
A. No error
B. SyntaxError
C. IndentationError
D. Logical Error
✅ Answer: A
Explanation: Valid code, prints "Yes".
15.
print("2" * "3")
A. SyntaxError
B. TypeError
C. No error
D. Logical Error
✅ Answer: B
Explanation: String cannot be multiplied by string.
16.
for i in 5:
print(i)
A. TypeError – int not iterable
B. No error
C. SyntaxError
D. Logical Error
✅ Answer: A
Explanation: Integer is not iterable.
17.
print("Python"[-10])
A. IndexError
B. No error
C. TypeError
D. ValueError
✅ Answer: A
Explanation: Negative index beyond string length.
18.
if True:
print("Yes")
else:
print("No")
A. IndentationError
B. SyntaxError
C. No error
D. ValueError
✅ Answer: A
Explanation: else not aligned properly.
19.
x = {"a":1, "b":2}
print(x["c"])
A. KeyError
B. SyntaxError
C. No error
D. TypeError
✅ Answer: A
Explanation: "c" not found in dictionary.
20.
print("Hello", end = )
A. SyntaxError
B. No error
C. IndentationError
D. ValueError
✅ Answer: A
Explanation: end requires a string, missing value → SyntaxError.
21.
print(2 ** 1000)
A. OverflowError
B. SyntaxError
C. No error – prints a big number
D. ValueError
✅ Answer: C
Explanation: Python supports arbitrarily large integers.
1.
if 5 < 10:
print("Yes")
A. Yes
B. YES
C. "Yes"
D. Error
✅ Answer: A
Explanation: Condition true → prints Yes (without quotes).
2.
x = 7
if x % 2 == 0:
print("Even")
else:
print("Odd")
A. Even
B. Odd
C. 7
D. Error
✅ Answer: B
Explanation: 7 is odd → prints "Odd".
3.
x = 10
if x == 10:
print("Ten")
A. Ten
B. "Ten"
C. 10
D. Error
✅ Answer: A
4.
a = 3
b = 4
if a + b == 7:
print("Correct")
A. 7
B. Correct
C. "Correct"
D. Error
✅ Answer: B
5.
if True:
print("Python")
A. Python
B. "Python"
C. True
D. Error
✅ Answer: A
6.
if False:
print("Hi")
else:
print("Bye")
A. Hi
B. Bye
C. Error
D. False
✅ Answer: B
7.
x = 5
if x > 10:
print("Big")
else:
print("Small")
A. Big
B. Small
C. Error
D. 5
✅ Answer: B
8.
x = 15
if x < 10:
print("A")
elif x < 20:
print("B")
else:
print("C")
A. A
B. B
C. C
D. Error
✅ Answer: B
9.
if 2 * 2 == 4:
print("Right")
else:
print("Wrong")
A. Right
B. Wrong
C. Error
D. 4
✅ Answer: A
10.
x = 9
if x % 3 == 0:
print("Divisible")
else:
print("Not Divisible")
A. Divisible
B. Not Divisible
C. Error
D. 9
✅ Answer: A
11.
if "a" in "apple":
print("Found")
A. Found
B. Error
C. apple
D. a
✅ Answer: A
12.
if len("Python") == 6:
print("Length OK")
A. Python
B. Length OK
C. 6
D. Error
✅ Answer: B
13.
x = 0
if not x:
print("Zero")
A. Zero
B. 0
C. False
D. Error
✅ Answer: A
Explanation: not 0 → True.
14.
if 5 > 2 and 2 > 1:
print("Valid")
A. Valid
B. True
C. Error
D. 5>2
✅ Answer: A
15.
if 5 > 10 or 10 > 5:
print("Yes")
else:
print("No")
A. Yes
B. No
C. Error
D. True
✅ Answer: A
16.
x = 4
if x == 5:
print("Equal")
else:
print("Not Equal")
A. Equal
B. Not Equal
C. Error
D. 4
✅ Answer: B
17.
if "x" not in "Python":
print("True")
else:
print("False")
A. True
B. False
C. Error
D. Python
✅ Answer: A
18.
if 10 != 5:
print("OK")
A. OK
B. Error
C. 10
D. False
✅ Answer: A
19.
if 2**3 == 8:
print("Power")
A. Power
B. Error
C. 8
D. True
✅ Answer: A
20.
x = 100
if x >= 100:
print("Pass")
else:
print("Fail")
A. Pass
B. Fail
C. Error
D. 100
✅ Answer: A
21.
if " " in "Hello World":
print("Space Found")
A. Space Found
B. Error
C. World
D. Hello
✅ Answer: A
1.
x = 5
if x > 2:
print("Big")
else:
print("Small")
A. SyntaxError – else misaligned
B. Logical Error
C. No error
D. Missing colon
✅ Answer: A
Explanation: The else must align with if. Misaligned indentation causes SyntaxError.
2.
if x > 10
print("Greater")
A. IndentationError
B. Missing colon
C. NameError
D. No error
✅ Answer: B
Explanation: Colon (:) is missing after condition.
3.
if True:
print("Yes")
A. No error
B. IndentationError
C. Logical Error
D. NameError
✅ Answer: B
Explanation: The print must be indented inside if.
4.
x = 10
if x = 10:
print("Ten")
A. No error
B. SyntaxError – wrong operator
C. ValueError
D. TypeError
✅ Answer: B
Explanation: Assignment = is not allowed inside condition; must use ==.
5.
if 5 < 10:
print("Yes")
A. Yes
B. "Yes"
C. Error
D. YES
✅ Answer: A
Explanation: Condition is true → prints Yes.
6.
if 5 > 10:
print("A")
else
print("B")
A. SyntaxError – missing colon
B. Logical Error
C. No error
D. IndentationError
✅ Answer: A
Explanation: else: must have colon.
7.
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
A. SyntaxError – misaligned elif
B. Logical Error
C. No error
D. IndentationError
✅ Answer: A
Explanation: elif must align with if.
8.
if 2 * 2 = 4:
print("Math")
A. Logical Error
B. SyntaxError
C. ValueError
D. No error
✅ Answer: B
Explanation: = cannot be used in condition.
9.
if (5 > 2)
print("Yes")
A. Missing colon
B. IndentationError
C. No error
D. Logical Error
✅ Answer: A
Explanation: Colon : missing.
10.
if True:
print("Hello")
print("World")
else:
print("Bye")
A. IndentationError – else misaligned
B. Logical Error
C. No error
D. Missing colon
✅ Answer: A
11.
if x > 10:
print("Big")
else:
print("Small")
A. No error
B. Logical Error
C. Missing colon
D. IndentationError
✅ Answer: A
12.
if 5 < 3:
print("Wrong")
A. IndentationError
B. Logical Error
C. No error
D. Missing colon
✅ Answer: A
13.
if "a" in "apple"
print("Found")
A. IndentationError
B. Missing colon
C. Logical Error
D. No error
✅ Answer: B
14.
if x > 0:
print("Positive")
else:
print("Non-positive")
A. IndentationError
B. Missing colon
C. No error
D. Logical Error
✅ Answer: A
15.
if not 0:
print("Zero")
A. Zero
B. IndentationError
C. No error
D. Logical Error
✅ Answer: A
Explanation: not 0 → True.
16.
if True:
print("OK")
else:
print("Not OK")
else:
print("Again")
A. SyntaxError – multiple else
B. Logical Error
C. No error
D. IndentationError
✅ Answer: A
17.
if x > 10:
print("A")
elif x < 5:
print("B")
else:
print("C")
A. IndentationError
B. No error
C. Missing colon
D. SyntaxError
✅ Answer: A
Explanation: else must align with if.
18.
if x > 0:
print("Positive")
elif:
print("Zero")
A. SyntaxError – elif needs condition
B. No error
C. IndentationError
D. Missing colon
✅ Answer: A
19.
if True print("Yes")
A. SyntaxError
B. IndentationError
C. No error
D. Logical Error
✅ Answer: A
Explanation: Missing : and newline/indent.
20.
if x > 5:
print("High")
else
print("Low")
A. SyntaxError – missing colon
B. IndentationError
C. Logical Error
D. No error
✅ Answer: A
1.
for i in range(3):
print(i)
A. SyntaxError
B. IndentationError
C. TypeError
D. No error
✅ Answer: B
Explanation: The print(i) must be indented inside the loop.
2.
for i in range(3):
print(i)
A. 0 1 2
B. 1 2 3
C. Error
D. Infinite loop
✅ Answer: A
Explanation: range(3) → 0,1,2.
3.
for i in range(1,4):
print(i)
A. 0 1 2
B. 1 2 3
C. 1 2 3 4
D. Error
✅ Answer: B
4.
for i in range(2,10,3):
print(i)
A. 2 5 8
B. 2 3 4
C. 2 10
D. Error
✅ Answer: A
Explanation: Start=2, stop=10, step=3.
5.
for i in range(5,2,-1):
print(i)
A. 5 4 3
B. 2 3 4 5
C. 5 2
D. Error
✅ Answer: A
6.
for i in "Hi":
print(i)
A. H i
B. Hi
C. Error
D. Loop never runs
✅ Answer: A
Explanation: Loops over each character.
7.
for i in range(0):
print("Run")
A. Run
B. Run Run
C. Nothing prints
D. Error
✅ Answer: C
Explanation: range(0) → empty sequence.
8.
i = 0
while i < 3:
print(i)
i += 1
A. 0 1 2
B. 1 2 3
C. Infinite loop
D. Error
✅ Answer: A
9.
i = 1
while i < 3:
print("Yes")
A. Yes Yes … (infinite)
B. Yes Yes
C. Error
D. No output
✅ Answer: A
Explanation: i never increments → infinite loop.
10.
for i in range(3):
print("Hello", i)
A. Hello 0 Hello 1 Hello 2
B. Hello 1 Hello 2 Hello 3
C. Hello Hello Hello
D. Error
✅ Answer: A
11.
for i in range(3):
print("Hi")
A. No error
B. IndentationError
C. SyntaxError
D. Logical Error
✅ Answer: B
12.
for i in range(2):
for j in range(2):
print(i, j)
A. 0 0 0 1 1 0 1 1
B. 0 0 0 1 1 0 1 1
C. 0 0 0 1 1 0 1 1 (same repeated)
D. 0 0 0 1 1 0 1 1
✅ Answer: A
Explanation: Runs nested loops → (0,0), (0,1), (1,0), (1,1).
13.
for i in range(5,5):
print(i)
A. 5
B. Nothing prints
C. Error
D. Infinite loop
✅ Answer: B
14.
for i in range(3,0,-1):
print(i)
A. 3 2 1
B. 1 2 3
C. Nothing
D. Error
✅ Answer: A
15.
for i in range(1,10,0):
print(i)
A. 1 to 9
B. 1 1 1 … infinite
C. ValueError
D. Error
✅ Answer: C
Explanation: Step cannot be 0.
16.
for i in [1,2,3]:
print(i*2)
A. 2 4 6
B. 1 2 3
C. Error
D. 12 22 3*2
✅ Answer: A
17.
for i in range(3):
pass
print("Done")
A. Done
B. 0 1 2 Done
C. Nothing
D. Error
✅ Answer: A
Explanation: pass means do nothing inside loop.
18.
i = 0
while i < 3:
print(i)
i = i + 2
A. 0 2
B. 0 1 2
C. 0 2 4
D. Infinite
✅ Answer: A
19.
for i in range(3):
print("Loop")
else:
print("End")
A. Loop Loop Loop
B. Loop Loop Loop End
C. End only
D. Error
✅ Answer: B
Explanation: Python for-else runs else if loop completes normally.
20.
for i in range(3):
print(i)
break
A. 0 1 2
B. 0 only
C. 1 only
D. Error
✅ Answer: B
Explanation: break exits loop after first iteration.