Loops Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q21
What will this code output: for i in range(1, 6): if i == 3: continue print(i, end=" ")
  • A 1 2 4 5
  • B 1 2 3 4 5
  • C 1 2
  • D 4 5
Answer: Option A
Explanation: When i equals 3, continue skips the print statement, so 3 is not printed.
Q22
Which method is used to iterate over dictionary key-value pairs?
  • A dict.keys()
  • B dict.values()
  • C dict.items()
  • D dict.pairs()
Answer: Option C
Explanation: items() method returns key-value pairs as tuples during dictionary iteration.
Q23
What is the output of: numbers = [1, 2, 3] for num in numbers: if num % 2 == 0: break print(num)
  • A 1
  • B 1 2
  • C 1 3
  • D 1 2 3
Answer: Option A
Explanation: The loop breaks when it encounters the first even number (2), so only 1 is printed.
Q24
How to reverse iterate through a list in Python?
  • A Using reverse()
  • B Using reversed()
  • C Using backward()
  • D Using invert()
Answer: Option B
Explanation: reversed() function or slicing [::-1] can be used to iterate through a list in reverse order.
Q25
What does the range() function with three parameters represent?
  • A start, stop, step
  • B begin, end, increment
  • C first, last, jump
  • D initial, final, skip
Answer: Option A
Explanation: range(start, stop, step) generates numbers from start to stop-1, incrementing by step.
Questions and Answers for Competitive Exams Various Entrance Test