Question 1
What is the purpose of Python’s interpreter?
A) To compile code into machine language
B) To execute code line by line
C) To debug syntax errors automatically
D) To convert Python to another programming language
Question 2
What will the following code print?
print(0o17)
A) 15
B) 17
C) 14
D) Error
Question 3
Which is a valid Python keyword?
A) run
B) and
C) execute
D) start
Question 4
What will print(6 << 2) output?
A) 12
B) 24
C) 3
D) Error
Question 5
What does # do in Python code?
A) Multiplies two numbers
B) Marks the start of a comment
C) Defines a variable
D) Ends a statement
Question 6
What is the data type of 0.001?
A) int
B) float
C) str
D) bool
Question 7
What will the following code print?
x = 5
x += 4
print(x)
A) 5
B) 9
C) 20
D) Error
Question 8
What is the output of:
print("Code"[0:2])
A) Co
B) od
C) de
D) Error
Question 9
What will print(int("7") + float("2.3")) output?
A) 9.3
B) 9
C) "9.3"
D) Error
Question 10
What is the result of "Star" * 2?
A) StarStar
B) Star 2
C) Star*2
D) Error
Question 11
Which variable name is invalid?
A) user_name
B) user2name
C) 2name
D) userName
Question 12
What will the following code print?
x = 10
if x <= 5:
print("Low")
elif x <= 15:
print("Medium")
else:
print("High")
A) Low
B) Medium
C) High
D) Error
Question 13
What is the output of:
for i in range(2, 6, 2):
print(i, end=" ")
A) 2 4
B) 2 3 4 5
C) 3 5
D) 2 4 6
Question 14
What will the following code print?
x = 7
while x > 4:
print(x)
x -= 1
A) 7 6 5 4
B) 7 6 5
C) 6 5 4
D) 4 5 6 7
Question 15
What is the output of:
for i in range(4):
if i % 2 == 1:
continue
print(i)
A) 0 2
B) 1 3
C) 0 1 2 3
D) Error
Question 16
What does not (3 > 5) evaluate to?
A) True
B) False
C) None
D) Error
Question 17
What is the output of:
for i in range(2):
for j in range(2):
print(i, end=" ")
A) 0 1
B) 0 0 1 1
C) 1 1 0 0
D) 0 1 0 1
Question 18
What will the following code print?
x = 1
while x < 5:
x += 2
print(x, end=" ")
A) 1 3 5
B) 3 5
C) 1 2 3 4
D) 3 5 7
Question 19
What does the break statement do in a loop?
A) Skips the current iteration
B) Exits the loop entirely
C) Repeats the loop
D) Pauses the loop
Question 20
Which condition evaluates to True?
A) 4 <= 3
B) 2 != 2
C) 5 >= 5
D) 1 > 2
Question 21
What will the following code print?
def square(num):
return num * num
print(square(4))
A) 8
B) 16
C) 4
D) Error
Question 22
What is the output of:
tup = (3, 6, 9)
print(tup[-2])
A) 3
B) 6
C) 9
D) Error
Question 23
What will the following code print?
d = {"x": 10, "y": 20}
print(d.get("z", 0))
A) 10
B) 20
C) 0
D) Error
Question 24
What is the output of:
def update(x):
x = 100
num = 50
update(num)
print(num)
A) 100
B) 50
C) None
D) Error
Question 25
What will the following code print?
lst = [2, 5, 1]
lst.sort()
print(lst[1])
A) 1
B) 2
C) 5
D) Error
Question 26
What is the output of:
tup = (1, 1, 2)
print(tup.count(1))
A) 1
B) 2
C) 3
D) Error
Question 27
What will the following code print?
d = {"a": 5}
d["b"] = 10
print(d)
A) {"a": 5}
B) {"a": 5, "b": 10}
C) {"b": 10}
D) Error
Question 28
What is the output of:
def greet(name, msg="Hello"):
return msg + ", " + name
print(greet("Alice"))
A) Hello, Alice
B) Alice, Hello
C) Hello Alice
D) Error
Question 29
What will the following code print?
lst = [1, 2, 3, 4]
lst.pop(2)
print(lst)
A) [1, 2, 4]
B) [1, 3, 4]
C) [2, 3, 4]
D) Error
Question 30
What will [x for x in range(5) if x % 2 == 1] produce?
A) [0, 2, 4]
B) [1, 3]
C) [1, 3, 5]
D) Error