Control Structures - boolean operators, conditional statements, loops for-while, break and continue - Question Bank
1. Consider the code: `count = 5
while count > 0:
print(count)
count -= 2`. What is the output?
2. What is the primary purpose of `elif`?
3. Which expression evaluates to `False`?
4. What does the `else` block associated with a `for` loop do?
5. Consider the code: `for i in range(4):
if i % 2 != 0:
print(i)`. What is the output?
6. Which keyword is used to create a loop that continues as long as a specified condition remains true?
7. What is the result of `True or (False and True)`?
8. Which boolean operator is used for checking inequality?
9. Consider the code: `while 5 > 3:
print('Hello')
break`. What is the output?
10. What is the difference between `for i in range(3)` and `for i in [0, 1, 2]`?
11. Which keyword is used to define a block of code that is executed if the preceding `if` or `elif` conditions are all false?
12. What does `x = 10; y = 5; print(x > y or x < y)` output?
13. Consider the code: `my_list = [1, 2, 3]
for item in my_list:
if item == 2:
continue
print(item)`. What is the output?
14. Which loop is guaranteed to execute at least once, even if the condition is false?
15. What is the purpose of indentation in Python's control structures?
16. Consider the code: `i = 0
while True:
print('Looping')
if i == 2:
break
i += 1`. What is the output?
17. Which statement allows executing code if an `if` condition is true, and another block of code if it's false?
18. What does the expression `5 > 3 and 10 < 20` evaluate to?
19. Consider the code: `for i in range(1, 5):
print(i)`. What is the output?
20. Which boolean operator has the highest precedence?
21. What is the primary use of the `range()` function with a `for` loop?
22. Consider the code: `num = 10
if num % 2 == 0:
print('Even')
else:
print('Odd')`. What will be printed?
23. Which control structure is used for error handling in Python?
24. What is the result of `not True`?
25. Which statement is used to create a loop that runs for a specific number of times using a sequence?
26. What happens if the condition in a `while` loop is initially `False`?
27. Which of the following correctly represents a boolean expression in Python?
28. Consider the code: `for i in 'Python':
if i == 'h':
continue
print(i, end='')`. What is the output?
29. What is the purpose of `pass` statement in Python?
30. In a nested conditional statement, the inner `if` belongs to which block?
31. What is the result of `True or False`?
32. Which operator returns `True` if at least one of the operands is true, and `False` otherwise?
33. Consider the code: `for i in range(5):
if i == 3:
break
print(i)`. What is the output?
34. Which of the following is an example of an iterable in Python suitable for a `for` loop?
35. What does the `not` operator do in Python?
36. Which statement is used to execute a block of code when an `if` condition evaluates to `False` and there is no `elif` condition met?
37. Consider the code: `count = 0
while count < 3:
print(count)
count += 1`. What is the output?
38. What is the primary difference between `if` and `elif`?
39. Which keyword allows checking multiple conditions sequentially after an initial `if` statement?
40. What is the result of the expression `True and False`?
41. Which operator returns `True` if both operands are true, and `False` otherwise?
42. The `for` loop in Python iterates over items in which of the following?
43. Consider the following code: `x = 5
if x > 10:
print('A')
else:
print('B')`. What will be printed?
44. Which loop is typically used when the number of iterations is known beforehand?
45. What is the purpose of the `continue` statement in a Python loop?
46. Which keyword is used to define a block of code that executes only if a preceding `if` condition is false?
47. What does the `break` statement do within a loop?
48. Which of the following is NOT a boolean operator in Python?
49. What is the primary function of a `while` loop in Python?
50. Which keyword is used to start a conditional statement in Python?