Exercise Solutions Available
Step-by-step answers for all textbook questions in this chapter
Control Structures — TN Class 11 CS Exercise Solutions
Complete exercise solutions for the Tamil Nadu Board Class 11 Computer Science chapter Control Structures. Covers if, if-else, elif, for, while, nested loops, break, and continue with working Python code.
How to Use This Page
1. Attempt each exercise on your own first — write code on paper or in IDLE before checking. 2. Trace through every program — manually follow variable values line by line to understand flow. 3. Run all code examples — copy each program into IDLE or a Python editor and verify the output. 4. Modify and experiment — change values, conditions, and loop ranges to deepen understanding. 5. Note indentation — Python uses indentation to define blocks. Wrong indentation causes errors.
Key Concepts (Quick Recap)
| Concept | Syntax | Purpose |
|---|---|---|
if | if condition: | Execute block only if condition is True |
if-else | if condition: ... else: ... | Choose between two alternatives |
elif | if c1: ... elif c2: ... else: ... | Choose among multiple alternatives |
for loop | for var in range(): | Iterate a known number of times |
while loop | while condition: | Repeat as long as condition is True |
range() | range(start, stop, step) | Generate sequence of numbers |
break | break | Exit the loop immediately |
continue | continue | Skip current iteration, go to next |
| Nested loop | Loop inside another loop | Handle tables, patterns, matrices |
Range Function:
| Call | Sequence Generated |
|---|---|
range(5) | 0, 1, 2, 3, 4 |
range(1, 6) | 1, 2, 3, 4, 5 |
range(1, 10, 2) | 1, 3, 5, 7, 9 |
range(10, 0, -1) | 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 |
Code Examples:
# if statement
age = 18
if age >= 18:
print("Eligible to vote")
# if-else statement
num = 7
if num % 2 == 0:
print(num, "is even")
else:
print(num, "is odd")
# elif ladder
marks = 85
if marks >= 90:
print("Grade A")
elif marks >= 80:
print("Grade B")
elif marks >= 70:
print("Grade C")
else:
print("Grade D")
# for loop
for i in range(1, 6):
print(i, end=" ") # Output: 1 2 3 4 5
# while loop
count = 1
while count <= 5:
print(count, end=" ") # Output: 1 2 3 4 5
count += 1
I. Choose the Best Answer (MCQs)
Q1. Which control structure is used to repeat a block of code multiple times? (a) Sequential (b) Selection (c) Iterative (d) None of these
Iterative control structures (for loop, while loop) are used to repeat a block of code. Sequential executes line by line, and Selection (if-else) makes decisions.
Q2. What will range(1, 5) generate? (a) 1, 2, 3, 4, 5 (b) 0, 1, 2, 3, 4 (c) 1, 2, 3, 4 (d) 1, 2, 3, 4, 5, 6
range(1, 5) starts at 1 and goes up to (but does not include) 5, generating 1, 2, 3, 4.
Q3. The break statement is used to: (a) Skip the current iteration (b) Exit the loop immediately (c) Continue the loop (d) Restart the loop
The break statement terminates the loop completely and execution continues with the statement after the loop.
for i in range(3):
print(i, end=" ")
range(3) generates 0, 1, 2 (starts at 0, goes up to but not including 3).
Q5. In a while loop, the condition is checked: (a) At the end of the loop (b) At the beginning of each iteration (c) Only once (d) Never
In a while loop, the condition is tested before each iteration. If the condition is False initially, the loop body is never executed.
Q6. What will range(0, 10, 2) generate? (a) 0, 1, 2, 3, 4, 5 (b) 0, 2, 4, 6, 8 (c) 2, 4, 6, 8, 10 (d) 1, 3, 5, 7, 9
range(0, 10, 2) starts at 0, goes up to (but not including) 10, with step 2: 0, 2, 4, 6, 8.
Q7. Which keyword is used to skip the current iteration and continue with the next? (a) break (b) pass (c) continue (d) skip
The continue statement skips the rest of the current iteration and moves to the next iteration of the loop.
II. Fill in the Blanks
1. The if statement is used to execute a block of code only when a condition is True. 2. The else clause is executed when the condition in the if statement is False. 3. The elif keyword is short for "else if" and is used to check multiple conditions. 4. A for loop is used when the number of iterations is known in advance. 5. A while loop is used when the number of iterations depends on a condition. 6. The range(5) function generates the sequence 0, 1, 2, 3, 4. 7. The range(1, 6) function generates the sequence 1, 2, 3, 4, 5. 8. The break statement is used to exit a loop immediately. 9. The continue statement skips the current iteration and moves to the next. 10. Python uses indentation to define the body of loops and conditional statements. 11. The three types of control structures are sequential, selection, and iterative. 12. In range(start, stop, step), the stop value is not included in the sequence. 13. A loop inside another loop is called a nested loop. 14. The else clause with a for loop executes when the loop completes normally (without break).
III. True or False (with corrections for false statements)
elif statement can be used without an if statement.while loop may execute zero times if the condition is initially False.break statement skips the current iteration and continues with the next.range(10) and range(0, 10) generate the same sequence.for loop can iterate over a string.else clause of a loop executes when the loop is terminated by break.IV. Match the Following
| Column A | Column B |
|---|---|
1. if | (d) Execute when condition is True |
2. else | (e) Execute when condition is False |
3. elif | (a) Check additional conditions |
4. for | (b) Loop with known iterations |
5. while | (c) Loop with condition |
6. break | (f) Exit loop immediately |
| Column A | Column B |
|---|---|
1. range(5) | (c) 0, 1, 2, 3, 4 |
2. range(1, 5) | (f) 1, 2, 3, 4 |
3. range(0, 10, 2) | (a) 0, 2, 4, 6, 8 |
4. range(10, 0, -1) | (b) 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 |
5. range(1, 10, 3) | (e) 1, 4, 7 |
6. range(5, 0, -1) | (d) 5, 4, 3, 2, 1 |
V. Answer Briefly (2-Mark Questions)
for loop and while loop.range() function? Give two examples.break and continue?if-elif-else ladder.if condition1:
# block executed if condition1 is True
elif condition2:
# block executed if condition1 is False and condition2 is True
elif condition3:
# block executed if conditions 1 and 2 are False and condition3 is True
else:
# block executed if all conditions are False
VI. Answer in Detail (5-Mark Questions)
Common Mistakes to Avoid
1. Forgetting the colon (:) after if, elif, else, for, while — Every control structure must end with a colon.
2. Incorrect indentation — Python requires consistent indentation (4 spaces) for blocks. Mixing tabs and spaces causes errors.
3. Infinite while loops — Always update the loop variable inside a while loop. Forgetting i += 1 creates an infinite loop.
4. Confusing = and == in conditions — Use == for comparison in conditions. if x = 5: is a syntax error (or unintended assignment). Correct: if x == 5:.
5. Off-by-one errors with range() — range(5) generates 0–4 (5 numbers), not 1–5. Use range(1, 6) for 1–5.
6. Using break and continue incorrectly — break exits the entire loop; continue only skips the current iteration. Don't confuse them.
7. elif without if — elif must always come after an if. It cannot start a conditional block on its own.
8. Missing loop variable update in while — A while loop needs its condition to eventually become False. If the variable controlling the condition is never updated, the loop runs forever.
Exam Checklist
Before your exam, make sure you can:
- [ ] Write if, if-else, and if-elif-else statements with correct syntax
- [ ] Use indentation properly in Python blocks
- [ ] Differentiate between for and while loops with examples
- [ ] Use range() with one, two, and three arguments
- [ ] Write programs: factorial, palindrome, Fibonacci, Armstrong, sum of digits
- [ ] Use break and continue correctly in loops
- [ ] Write nested loops for patterns and tables
- [ ] Trace through loop execution manually (variable values at each step)
- [ ] Identify and fix infinite loop situations
- [ ] Draw flowcharts for if-else and loop structures
- [ ] Write programs using all three control structures together
