Current Affairs updated daily
KalviGavaniKalviGavani

Control Structures Exercise Solutions | KalviGavani

TN Class 11 CS Control Structures exercise solutions — if, if-else, elif, for loop, while loop, nested loops with Python code examples and exam tips.

Updated 15 June 202616 min read

Exercise Solutions Available

Step-by-step answers for all textbook questions in this chapter

View Solutions →

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)

ConceptSyntaxPurpose
ifif condition:Execute block only if condition is True
if-elseif condition: ... else: ...Choose between two alternatives
elifif c1: ... elif c2: ... else: ...Choose among multiple alternatives
for loopfor var in range():Iterate a known number of times
while loopwhile condition:Repeat as long as condition is True
range()range(start, stop, step)Generate sequence of numbers
breakbreakExit the loop immediately
continuecontinueSkip current iteration, go to next
Nested loopLoop inside another loopHandle tables, patterns, matrices

Range Function:

CallSequence 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

Answer(c) Iterative

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

Answer(c) 1, 2, 3, 4

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

Answer(b) Exit the loop immediately

The break statement terminates the loop completely and execution continues with the statement after the loop.


Q4. What is the output of the following code?
for i in range(3):
    print(i, end=" ")
Answer

(a) 1 2 3 (b) 0 1 2 (c) 0 1 2 3 (d) 1 2

Answer(b) 0 1 2

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

Answer(b) At the beginning of each iteration

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

Answer(b) 0, 2, 4, 6, 8

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

Answer(c) continue

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)

Q1. The elif statement can be used without an if statement.
Answer

False. The elif statement must always follow an if statement. It cannot be used independently. The correct structure is: if ... elif ... elif ... else.


Q2. A while loop may execute zero times if the condition is initially False.
Answer

True. The while loop checks the condition before each iteration. If the condition is False at the start, the loop body is never executed.


Q3. The break statement skips the current iteration and continues with the next.
Answer

False. The continue statement skips the current iteration and continues with the next. The break statement exits the loop entirely.


Q4. Indentation is optional in Python loops and conditions.
Answer

False. Indentation is mandatory in Python. It defines which statements belong to the loop or condition block. Wrong indentation causes an IndentationError.


Q5. range(10) and range(0, 10) generate the same sequence.
Answer

True. range(10) defaults to start=0, so it generates 0, 1, 2, ..., 9. range(0, 10) explicitly starts at 0 and generates the same sequence.


Q6. A for loop can iterate over a string.
Answer

True. A for loop can iterate over any sequence — strings, lists, tuples, etc. Iterating over a string gives each character.

for ch in "Hello":
    print(ch, end=" ")  # Output: H e l l o

Q7. The else clause of a loop executes when the loop is terminated by break.
Answer

False. The else clause of a loop executes only when the loop completes normally (without encountering a break). If the loop is terminated by break, the else block is skipped.


IV. Match the Following

Column AColumn 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
Answer1–d, 2–e, 3–a, 4–b, 5–c, 6–f

Column AColumn 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
Answer1–c, 2–f, 3–a, 4–b, 5–e, 6–d

V. Answer Briefly (2-Mark Questions)

Q1. Differentiate between for loop and while loop.
Answer
Featurefor loopwhile loop
Use caseKnown number of iterationsUnknown number of iterations
Syntaxfor var in sequence:while condition:
IterationOver a sequence (range, list, string)Based on a condition
Examplefor i in range(5):while i < 5:
Risk of infinite loopLow (bounded by sequence)High (if condition never becomes False)

Q2. What is the range() function? Give two examples.
Answer

The range() function generates a sequence of numbers. It takes up to three arguments: range(start, stop, step).

# Example 1: range(stop) — starts at 0
for i in range(4):
    print(i, end=" ")  # Output: 0 1 2 3

# Example 2: range(start, stop, step) — custom step
for i in range(2, 11, 2):
    print(i, end=" ")  # Output: 2 4 6 8 10

Q3. What is the difference between break and continue?
Answer
Featurebreakcontinue
ActionExits the loop completelySkips current iteration only
Loop continues?NoYes (next iteration)
Use caseExit when a specific condition is metSkip certain values
ExampleFind an item and stop searchingSkip even numbers in a range
# break example
for i in range(1, 10):
    if i == 5:
        break
    print(i, end=" ")  # Output: 1 2 3 4

# continue example
for i in range(1, 6):
    if i == 3:
        continue
    print(i, end=" ")  # Output: 1 2 4 5

Q4. Write the syntax of an 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
Answer

Only the first True condition's block is executed. The rest are skipped even if they are also True.


VI. Answer in Detail (5-Mark Questions)

Q1. Explain the three types of control structures in Python with examples.
Answer

1. Sequential Control Structure: Statements are executed one after another in the order they appear, from top to bottom. This is the default flow.

# Sequential execution
name = input("Enter name: ")
age = int(input("Enter age: "))
print("Name:", name)
print("Age:", age)

2. Selection Control Structure (Conditional Statements): The program chooses between alternative paths based on conditions.

a) Simple if:

marks = 95
if marks >= 90:
    print("Outstanding performance!")

b) if-else:

age = int(input("Enter age: "))
if age >= 18:
    print("Eligible to vote")
else:
    print("Not eligible to vote")

c) if-elif-else (multiple conditions):

marks = int(input("Enter marks: "))
if marks >= 90:
    print("Grade A")
elif marks >= 80:
    print("Grade B")
elif marks >= 70:
    print("Grade C")
elif marks >= 60:
    print("Grade D")
else:
    print("Grade E")

3. Iterative Control Structure (Loops): The program repeats a block of code multiple times.

a) for loop:

# Print numbers 1 to 5
for i in range(1, 6):
    print(i, end=" ")  # Output: 1 2 3 4 5

b) while loop:

# Print numbers 1 to 5
i = 1
while i <= 5:
    print(i, end=" ")  # Output: 1 2 3 4 5
    i += 1

c) Nested loops:

# Print multiplication table for 1 to 3
for i in range(1, 4):
    for j in range(1, 4):
        print(i * j, end="\t")
    print()

Output:

1 2 3 2 4 6 3 6 9

Q2. Write Python programs to: (a) Find the factorial of a number (b) Check if a number is a palindrome (c) Print a number pattern.
Answer

(a) Factorial of a number:

# Program to find factorial of a number
n = int(input("Enter a number: "))
fact = 1

if n < 0:
    print("Factorial does not exist for negative numbers")
elif n == 0:
    print("Factorial of 0 is 1")
else:
    for i in range(1, n + 1):
        fact = fact * i
    print("Factorial of", n, "is", fact)

Output:

Enter a number: 5 Factorial of 5 is 120

Trace for n=5: fact = 1×1 = 1, 1×2 = 2, 2×3 = 6, 6×4 = 24, 24×5 = 120

(b) Check if a number is a palindrome:

# Program to check if a number is a palindrome
n = int(input("Enter a number: "))
original = n
reverse = 0

while n > 0:
    digit = n % 10          # Get the last digit
    reverse = reverse * 10 + digit  # Build the reversed number
    n = n // 10             # Remove the last digit

if original == reverse:
    print(original, "is a palindrome")
else:
    print(original, "is not a palindrome")

Output:

Enter a number: 121 121 is a palindrome Enter a number: 123 123 is not a palindrome

Trace for n=121: digit=1, reverse=1, n=12 → digit=2, reverse=12, n=1 → digit=1, reverse=121, n=0 → 121 == 121 ✓

(c) Number pattern:

# Program to print number pattern
# 1
# 1 2
# 1 2 3
# 1 2 3 4
# 1 2 3 4 5

rows = int(input("Enter number of rows: "))
for i in range(1, rows + 1):
    for j in range(1, i + 1):
        print(j, end=" ")
    print()

Output:

Enter number of rows: 5 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5

Q3. Write Python programs using while loop to: (a) Find the sum of digits of a number (b) Print the Fibonacci series (c) Find whether a number is an Armstrong number.
Answer

(a) Sum of digits of a number:

# Program to find sum of digits
n = int(input("Enter a number: "))
original = n
sum_digits = 0

while n > 0:
    digit = n % 10       # Extract last digit
    sum_digits += digit  # Add to sum
    n = n // 10          # Remove last digit

print("Sum of digits of", original, "=", sum_digits)

Output:

Enter a number: 1234 Sum of digits of 1234 = 10

Trace: n=1234, digit=4, sum=4, n=123 → digit=3, sum=7, n=12 → digit=2, sum=9, n=1 → digit=1, sum=10, n=0

(b) Fibonacci series:

# Program to print Fibonacci series
n = int(input("Enter number of terms: "))
a, b = 0, 1
count = 0

print("Fibonacci series:")
while count < n:
    print(a, end=" ")
    a, b = b, a + b
    count += 1

Output:

Enter number of terms: 8 Fibonacci series: 0 1 1 2 3 5 8 13

Trace: (0,1)→print 0, (1,1)→print 1, (1,2)→print 1, (2,3)→print 2, (3,5)→print 3, (5,8)→print 5, (8,13)→print 8, (13,21)→print 13

(c) Armstrong number:

An Armstrong number (for 3 digits) is a number where the sum of cubes of its digits equals the number itself. Example: 153 = 1³ + 5³ + 3³ = 1 + 125 + 27 = 153.

# Program to check if a number is an Armstrong number
n = int(input("Enter a number: "))
original = n
sum_cubes = 0

while n > 0:
    digit = n % 10
    sum_cubes += digit ** 3
    n = n // 10

if original == sum_cubes:
    print(original, "is an Armstrong number")
else:
    print(original, "is not an Armstrong number")

Output:

Enter a number: 153 153 is an Armstrong number Enter a number: 123 123 is not an Armstrong number

Trace for 153: digit=3, sum=27, n=15 → digit=5, sum=27+125=152, n=1 → digit=1, sum=152+1=153, n=0 → 153 == 153 ✓


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

Frequently Asked Questions

Control structures direct the flow of a program. There are three types: sequential (default, line by line), selection (if, if-else, elif for decisions), and iterative (for, while loops for repetition).