Loading

Quipoin Menu

Learn • Practice • Grow

python-for-ai / Loops and Conditionals
mcq
Direction: Choose the correct option

Q1.

What is the output of `for i in range(3): print(i)`?
A. 1 2 3
B. 0 1 2 3
C. 1 2
D. 0 1 2
Direction: Choose the correct option

Q2.

Which keyword is used to exit a loop prematurely?
A. exit
B. break
C. continue
D. pass
Direction: Choose the correct option

Q3.

What does the `else` clause do in a loop?
A. Executes if loop never runs
B. Executes after each iteration
C. Executes only if break occurs
D. Executes if loop terminates normally (without break)
Direction: Choose the correct option

Q4.

Given `x = 10`, what will `if x: print(x) else: print('no')` output?
A. 10nno
B. Error
C. no
D. 10
Direction: Choose the correct option

Q5.

Which of the following is a valid one-line conditional expression (ternary operator)?
A. x = 5 if condition else 10
B. if condition: x=5 else: x=10
C. x = condition ? 5 : 10
D. x = 5 else 10
Direction: Choose the correct option

Q6.

What is the result of `[i for i in range(5) if i % 2 == 0]`?
A. [1,3]
B. [0,2,4,6]
C. [0,1,2,3,4]
D. [0,2,4]
Direction: Choose the correct option

Q7.

How do you skip the rest of the current iteration in a loop?
A. break
B. pass
C. continue
D. return
Direction: Choose the correct option

Q8.

What is the output of `i=0; while i<3: print(i); i+=1`?
A. 0 1 2 3
B. 0 1
C. 1 2 3
D. 0 1 2
Direction: Choose the correct option

Q9.

Which statement is used to do nothing as a placeholder?
A. pass
B. continue
C. None
D. break
Direction: Choose the correct option

Q10.

What is the output of `if None: print('True')`?
A. TRUE
B. Error
C. FALSE
D. Nothing