Chapter-4 Iterative Statements in Python — Online MCQ Test
INFORMATION TECHNOLOGY · Grade 8 · CBSE(NCERT)
Practice Chapter-4 Iterative Statements in Python with a free chapter-wise online MCQ test.
This chapter covers: control flow - iteration - for loop - while loop - infinite loop - loop variable - range function - membership operators.
AI-generated questions from basic to board-exam level, with instant results and explanations.
Chapter-4 Iterative Statements in Python — Important Questions & Answers
Which keyword is used to create a loop in Python that repeats a block of code?
- A. repeat
- B. loop
- C. for
- D. iterate
Answer: C. for
The 'for' keyword is used to create a for loop in Python, which is one of the primary iterative statements.
The 'for' keyword is used to create a for loop in Python, which is one of the primary iterative statements.
What is the purpose of the range() function in Python?
- A. To find the maximum value in a list
- B. To generate a sequence of numbers
- C. To check if a value exists in a list
- D. To convert a string to a number
Answer: B. To generate a sequence of numbers
The range() function generates a sequence of numbers, commonly used with for loops to repeat code a specific number of times.
The range() function generates a sequence of numbers, commonly used with for loops to repeat code a specific number of times.
Which of the following is a membership operator in Python?
- A. ==
- B. in
- C. and
- D. not
Answer: B. in
The 'in' operator is a membership operator used to check if a value exists in a sequence like lists, strings, or tuples.
The 'in' operator is a membership operator used to check if a value exists in a sequence like lists, strings, or tuples.
What will be the output of this code? for i in range(3): print(i)
- A. 1 2 3
- B. 0 1 2
- C. 0 1 2 3
- D. 1 2
Answer: B. 0 1 2
The loop prints values from range(3), which generates 0, 1, and 2. Each value is printed on a new line.
The loop prints values from range(3), which generates 0, 1, and 2. Each value is printed on a new line.
What will be the output? for i in range(1, 4): for j in range(1, 3): print(i, j)
- A. 1 1, 1 2, 2 1, 2 2, 3 1, 3 2
- B. 1 1, 2 1, 3 1
- C. 1 2, 2 2, 3 2
- D. 1 1, 1 2, 1 3
Answer: A. 1 1, 1 2, 2 1, 2 2, 3 1, 3 2
This is a nested loop. The outer loop runs for i = 1, 2, 3, and for each, the inner loop runs for j = 1, 2, producing all combinations.
This is a nested loop. The outer loop runs for i = 1, 2, 3, and for each, the inner loop runs for j = 1, 2, producing all combinations.