🚗
🤖
🗼 💻 🖥️ ðŸ§
🖥️
🗼
✨ Computer Science Examination Assessment ✨
COMPUTISM LAB
HALF YEARLY EXAMINATION
Loops in Python & Advanced Control Structures
ðŸ§
🤖
Standard: Python Programming
Max Marks: 100
Time Allowed: 3 Hours
Section A: Fill in the Blanks10 Marks
- The statement is used to terminate the loop prematurely even if the condition is not met.
- In Python, you can have an else block with a loop that is executed when the loop completes .
- The statement acts as an empty placeholder that does not do anything.
- A loop in Python is used to repeatedly execute a block of code as long as a specified condition remains True.
- To iterate over each character in a string using a for loop, we use the syntax .
- The statement skips the current iteration and moves to the next iteration.
- In a while loop, the condition is evaluated at the of each iteration.
- Multi-dimensional data handling can be efficiently achieved using loops.
- Python's famous Zen philosophy emphasizes that counts.
- The control variable in a range-based for loop automatically updates with each .
Section B: Multiple Choice Questions (MCQs)10 Marks
- Why do we use loops in Python?
- a. To make the code look longer
- b. To execute code only once
- c. To automate repetitive tasks
- d. To slow down execution
- Which type of loop is used to repeat a set of instructions for a specific number of times?
- a. When loop
- b. For loop
- c. Repeat loop
- d. Infinite loop
- What does the break statement do in a loop?
- a. Skips current iteration
- b. Continues the loop
- c. Exits loop prematurely
- d. Restarts program
- What is the purpose of the else block in a loop?
- a. Handles errors
- b. Executes on normal completion
- c. Runs on break
- d. Loops infinitely
- Which statement is used when we want to do nothing in code blocks?
- a. pass
- b. continue
- c. break
- d. skip
- What will be the output of `range(1, 6)` in a for loop?
- a. 1, 2, 3, 4, 5, 6
- b. 1, 2, 3, 4, 5
- c. 0, 1, 2, 3, 4, 5
- d. 2, 3, 4, 5, 6
- Which loop checks the condition before entering the block?
- a. while loop
- b. do-while loop
- c. repeat-until loop
- d. infinite loop
- What happens if a while loop's condition never becomes False?
- a. Syntax Error
- b. Indentation Error
- c. Infinite Loop
- d. Normal Termination
- Which keyword is used to skip the rest of the code for current iteration?
- a. break
- b. continue
- c. pass
- d. exit
- Nested loops refer to:
- a. Loops inside another loop
- b. Parallel loops
- c. Syntax error loops
- d. Conditionless loops
Section C: Assertion-Based MCQs10 Marks
-
Assertion (A): The `break` statement terminates the loop immediately when executed.
Reason (R): It transfers control to the statement immediately following the loop.
a) Both A and R are true, and R is the correct explanation of A.
b) Both are true, but unrelated.
c) A is true, R is false.
d) A is false, R is true. -
Assertion (A): A `while` loop is best used when the exact number of iterations is known in advance.
Reason (R): The `for` loop is specifically designed for iterating over sequences like strings or ranges.
a) Both A and R are true.
b) A is true, but R is false.
c) A is false, but R is true.
d) Both A and R are false. -
Assertion (A): The `pass` statement in Python causes a syntax error if left empty inside a loop.
Reason (R): `pass` acts as a null statement or placeholder that does nothing when executed.
a) Both are true.
b) A is true, R is false.
c) A is false, but R is true.
d) Both are false. -
Assertion (A): An `else` block associated with a `for` loop executes even if a `break` statement terminates the loop.
Reason (R): The loop-else block only executes when the loop finishes all iterations normally without breaking.
a) Both A and R are true, and R is the correct explanation of A.
b) A is true, R is false.
c) A is false, but R is true.
d) Both are false. -
Assertion (A): Infinite loops are always desirable in standard application programming.
Reason (R): They consume CPU resources continuously without terminating unless interrupted.
a) Both are true.
b) A is true, R is false.
c) A is false, but R is true.
d) Both are false. -
Assertion (A): The `continue` statement skips remaining statements inside the loop for the current iteration.
Reason (R): It jumps directly to the evaluation of the loop condition or next item.
a) Both A and R are true, and R is the correct explanation of A.
b) A is true, R is false.
c) A is false, but R is true.
d) Both are false. -
Assertion (A): Python allows loops to be nested inside one another.
Reason (R): Nested loops are useful for working with multi-dimensional data structures like tables.
a) Both A and R are true, and R is the correct explanation of A.
b) Both are true, unrelated.
c) A is true, R is false.
d) A is false, R is true. -
Assertion (A): The initialization of the loop control variable is automatically handled in a standard `for` loop using `range()`.
Reason (R): The `range()` function generates the sequence of numbers used by the loop automatically.
a) Both A and R are true, and R is the correct explanation of A.
b) A is true, R is false.
c) A is false, R is true.
d) Both are false. -
Assertion (A): A `while` loop will never execute its code block if the initial condition evaluates to False.
Reason (R): The condition is tested prior to entering the loop body.
a) Both A and R are true, and R is the correct explanation of A.
b) Both are true, unrelated.
c) A is true, R is false.
d) A is false, R is true. -
Assertion (A): Using meaningful variable names in loops enhances code readability.
Reason (R): Python's core design philosophy emphasizes code clarity and readability.
a) Both A and R are true, and R is the correct explanation of A.
b) Both are true, unrelated.
c) A is true, R is false.
d) A is false, R is true.
Section D: True or False10 Marks
- The `break` statement stops the loop execution immediately. (True / False)
- A `for` loop in Python cannot iterate through characters of a string. (True / False)
- The `else` block with a loop runs when the loop terminates via a `break` statement. (True / False)
- The `pass` statement is used as a temporary placeholder in code blocks. (True / False)
- A `while` loop requires the condition to eventually become False to avoid an infinite loop. (True / False)
- Nested loops mean having a loop inside another loop. (True / False)
- The `continue` statement exits the entire loop immediately. (True / False)
- Python's `range(1, 11)` generates numbers from 1 to 10. (True / False)
- Infinite loops are useful when creating servers that must run continuously. (True / False)
- Indentation is critical for defining the body of loops in Python. (True / False)
Section E: Short Answer Questions (2 Marks Each)10 Marks
- What is the difference between `break` and `continue` statements in Python loops?
- Explain the purpose of the `else` block used with loops in Python.
- What is an infinite loop? Give one scenario where it can occur accidentally.
- Define nested loops. Give a brief practical use case.
- What is the role of the `pass` statement in Python programming?
Section F: Python Programming Tasks (Final Question)25 Marks
-
Program 1: Using `break` statement
-
Program 2: Using `while` loop print all even no from 1 to 100
-
Program 3: Using `continue` statement
-
Program 4: Print all letter in new line of a String
-
Program 5: Loop with Else Block
Write a Python program that searches for a target number in a list and prints confirmation messages.
⭐ Best of Luck for Your Examination! Code with Confidence! 🚀
CREATED BY BIJAN KRISHNA PAUL
No comments:
Post a Comment