Get the most accurate TN Board Solutions for Class 12 Computer Science Chapter 06 Control Structures here. Updated for the 2026-27 academic session, these solutions are based on the latest TN Board textbooks for Class 12 Computer Science. Our expert-created answers for Class 12 Computer Science are available for free download in PDF format.
Detailed Chapter 06 Control Structures TN Board Solutions for Class 12 Computer Science
For Class 12 students, solving TN Board textbook questions is the most effective way to build a strong conceptual foundation. Our Class 12 Computer Science solutions follow a detailed, step-by-step approach to ensure you understand the logic behind every answer. Practicing these Chapter 06 Control Structures solutions will improve your exam performance.
Class 12 Computer Science Chapter 06 Control Structures TN Board Solutions PDF
I. Choose The Best Answer (1 Mark)
Question 1. How many important control structures are there in Python?
(a) 2
(b) 3
(c) 5
(d) 6
Answer: (b) 3
In simple words: Python uses three main control structures to guide how a program runs. These include sequential (steps in order), selection (making choices with if/else), and iteration (repeating actions with loops).
๐ฏ Exam Tip: Remember the three fundamental control structures: sequential, selection (or conditional), and iteration (or looping). Each helps manage program flow effectively.
Question 2. elif can be considered to be abbreviation of
(a) nested if
(b) if..else
(c) else if
(d) if..elif
Answer: (c) else if
In simple words: The word 'elif' is a shorter way to say 'else if' in programming. It helps to check many conditions one after another.
๐ฏ Exam Tip: Understanding `elif` as "else if" helps in writing cleaner code for multiple conditions, avoiding deeply nested `if-else` blocks.
Question 3. What plays a vital role in Python programming?
(a) Statements
(b) Control
(c) Structure
(d) Indentation
Answer: (d) Indentation
In simple words: In Python, spaces or tabs at the start of a line (indentation) are very important. They tell the computer which lines belong together as a block of code, like inside a loop or an 'if' statement. Without correct indentation, your program will not run.
๐ฏ Exam Tip: Python uses indentation to define code blocks, unlike many languages that use braces. Incorrect indentation will lead to syntax errors.
Question 4. Which statement is generally used as a placeholder?
(a) continue
(b) break
(c) pass
(d) goto
Answer: (c) pass
In simple words: The 'pass' statement in Python does nothing. It is used as a temporary placeholder when you need to have a statement in your code but don't want any action to happen yet. This helps prevent errors for empty code blocks.
๐ฏ Exam Tip: Use `pass` when a statement is syntactically required but you want to skip any processing for now, like in an empty function or loop body.
Question 5. The condition in the if statement should be in the form of
(a) Arithmetic or Relational expression
(b) Arithmetic or Logical expression
(c) Relational or Logical expression
(d) Arithmetic
Answer: (c) Relational or Logical expression
In simple words: The condition in an 'if' statement must be something that can be true or false. This means it uses comparison (relational) like 'greater than' or combines true/false statements (logical) like 'and' or 'or'.
๐ฏ Exam Tip: An `if` statement's condition evaluates to a Boolean value (True or False), so it must be formed using relational operators (like >, <, ==) or logical operators (like `and`, `or`, `not`).
Question 6. Which is the most comfortable loop?
(a) do..while
(b) while
(c) for
(d) if..elif
Answer: (c) for
In simple words: The 'for' loop is often seen as the easiest loop to use when you know exactly how many times you want to repeat something, or when you are going through a list of items. It simplifies many common repetitive tasks in programming.
๐ฏ Exam Tip: The `for` loop is ideal for iterating over a sequence (like a list, tuple, string, or range) or when the number of iterations is known beforehand.
Question 7. What is the output of the following snippet?
`i=1`
`while True:`
` if i%3 ==0:`
` break`
` i+=1`
(a) 12
(b) 123
(c) 1234
(d) 124
Answer: (a) 12
In simple words: The code starts with `i` as 1. It keeps adding 1 to `i` until `i` can be divided by 3 without any remainder. The first time `i` becomes divisible by 3 is when it reaches 3, and then the loop stops. However, the print statement is outside the loop and the code snippet does not print the final value of i. If the question implies what `i` would be just before the break, then `i` would be 3. Let's re-examine the question. This question asks for the output of the snippet. There is no `print` statement in the snippet shown, so the output should be nothing, or an error if the options are outputs of a different snippet. Given the options, it seems like there might be a missing `print(i)` somewhere inside or after the loop. If the intent was to print values *before* the loop breaks, and it runs until i%3==0, then i would be 1, then 2, then at 3 it breaks. If we assume the question implies printing values of 'i' that *don't* trigger the break, it would be 1 and 2. The option '12' could imply concatenated output of `print(1)` and `print(2)`. Let's assume there's an implicit `print(i)` *before* the `if` statement. If `print(i)` was before the `if` statement: `i=1` prints 1. `i=2` prints 2. `i=3`, `i%3==0` is true, it breaks. So the output would be 1 and 2. The option '12' seems to be a concatenation of 1 and 2. This is the most plausible interpretation with the given options.
๐ฏ Exam Tip: Always carefully trace the loop's execution, paying attention to where `print` statements are placed and when `break` conditions are met. If there is no print statement, the output should be nothing, unless implied by the options.
Question 8. What is the output of the following snippet?
`T=1`
`while T:`
` print(True)`
` break`
(a) False
(b) True
(c) 0
(d) No Output
Answer: (b) True
In simple words: The variable `T` is set to 1. In Python, 1 is considered `True`. So, the `while T` loop runs once. Inside the loop, it prints the word "True" to the screen. Then, the `break` command stops the loop immediately. Therefore, "True" is printed only once.
๐ฏ Exam Tip: Remember that in Python, non-zero numbers (like 1) are treated as `True` in boolean contexts, while 0 is `False`.
Question 9. Which amongst this is not a jump statement ?
(a) for
(b) goto
(c) continue
(d) break
Answer: (a) for
In simple words: Jump statements like 'goto', 'continue', and 'break' change the normal flow of a program in specific ways, often skipping parts or exiting loops. The 'for' statement, however, is a loop itself, meant for repeating actions a certain number of times or over a sequence, not for jumping.
๐ฏ Exam Tip: Distinguish between loop control statements (`for`, `while`) and jump statements (`break`, `continue`, `pass`, `goto` if available) which alter the flow within or out of loops/functions.
Question 10. Which punctuation should be used in the blank?
`if < condition >`
` statements-block 1`
`else:`
` statements-block 2`
(a) ;
(b) :
(c) ::
(d) !
Answer: (b) :
In simple words: In Python, after an `if` condition or an `else` keyword, you always need to put a colon (`:`) to show that a new block of code is starting. This is a basic rule of Python syntax.
๐ฏ Exam Tip: Python uses colons (`:`) to mark the end of a header line (like `if`, `else`, `for`, `while`, `def`, `class`) before an indented code block begins.
II. Answer The Following Questions (2 Marks)
Question 1. List the control structures in Python.
Answer: There are three main control structures in Python:
1. Sequential: This is when statements are executed one after another in the order they appear. It is the default flow of a program.
2. Alternative or Branching (Selection): This allows the program to make decisions and choose different paths based on conditions, using `if`, `else`, and `elif` statements.
3. Iterative or Looping (Repetition): This allows a block of code to be repeated multiple times, using `for` and `while` loops. Loops are efficient for performing repetitive tasks.
In simple words: Python programs follow three basic ways to run: doing things one after another (sequential), making choices (alternative), and repeating things (iterative).
๐ฏ Exam Tip: Clearly define each type of control structure and provide a basic example (e.g., `if` for alternative, `for` for iterative) if space allows.
Question 2. Write note on break statement.
Answer: The `break` statement in Python is used to stop a loop immediately. When `break` is executed:
- The control of the program jumps to the statement right after the loop's body.
- If the `break` statement is inside loops that are nested (a loop inside another loop), it will only stop the innermost loop where it is placed. The outer loop will continue to run.
In simple words: The 'break' statement makes a loop stop right away, sending the program to the code just after the loop. If loops are inside other loops, 'break' only stops the closest one.
๐ฏ Exam Tip: Emphasize that `break` exits the *current* loop entirely, not just the current iteration, and only affects the innermost loop in nested structures.
Question 3. Write is the syntax of if..else statement
Answer: The `if..else` statement in Python is used for decision-making. It runs one block of code if a condition is true, and a different block if the condition is false.
The general syntax for the `if..else` statement is:
`if < condition >:`
` statements โ block 1`
`else:`
` statements โ block 2`
The condition inside the `if` must be a relational or logical expression that evaluates to `True` or `False`.
In simple words: The 'if..else' command lets your program make a choice. If a condition is true, it does the first set of steps; if not, it does the second set of steps.
๐ฏ Exam Tip: Always include the colon (`:`) after `if
Question 4. Define control structure.
Answer: A control structure in programming is a statement or a block of statements that determines the order in which other instructions or statements are executed in a program. It allows a programmer to specify the flow of control through the program, making decisions, repeating tasks, or executing steps sequentially. These structures are crucial for creating dynamic and functional programs.
In simple words: A control structure is a special command that tells a computer program what steps to do and in what order, like making choices or repeating actions.
๐ฏ Exam Tip: Emphasize that control structures are the building blocks that dictate the *flow* or *order* of execution, which is fundamental to any algorithm.
Question 5. Write note on range () in loop
Answer: In Python, the `range()` function is often used with `for` loops to generate a sequence of numbers. It is very useful for iterating a specific number of times. The `range()` function can take one, two, or three arguments:
- `range(stop)`: Generates numbers from 0 up to (but not including) `stop`.
- `range(start, stop)`: Generates numbers from `start` up to (but not including) `stop`.
- `range(start, stop, step)`: Generates numbers from `start` up to (but not including) `stop`, with an increment of `step`.
In simple words: The `range()` function helps 'for' loops count numbers. You can tell it where to start, where to stop, and how much to count by, making it easy to repeat actions a specific number of times.
๐ฏ Exam Tip: Remember that `range()` generates numbers up to, but *not including*, the `stop` value, and it produces a range object, not an actual list.
III. Answer The Following Questions (3 Marks)
Question 1. Write a program to display
A
AB
ABC
ABCD
ABCDE
Answer: The program below uses nested `for` loops to print the desired pattern. The outer loop controls the number of characters in each line, and the inner loop prints the characters from 'A' up to the current line's length. The ASCII value of 'A' (65) is used to convert numbers to characters.
`For i in range (1,6,1):`
` ch=65`
` for j in range (ch,ch+i,1):`
` a=chr(j)`
` print (a, end =' ')`
` print ()`
This code will successfully produce the output, creating a triangular pattern of letters.
In simple words: This program uses two loops. The first loop decides how many letters are on each line, and the second loop picks and prints the actual letters (A, B, C, etc.) to make the pattern.
๐ฏ Exam Tip: For pattern-printing programs, observe how the number of characters and their values change in each row to determine the logic for inner and outer loops.
Question 2. Write note on if..else structure.
Answer: The `if-else` statement is a fundamental control structure that allows a program to execute different blocks of code based on whether a given condition is true or false. If the condition specified with `if` is true, the `if` block is executed. Otherwise, the `else` block is executed. This provides a way to implement decision-making logic in programs.
The syntax for an `if-else` statement is:
`if < condition >:`
` statements โ block 1`
`else:`
` statements โ block 2`
The condition is evaluated, and based on its Boolean result, one of the two code blocks is chosen for execution.
In simple words: The 'if-else' rule helps a computer program choose between two actions. If a condition is met, it does the first action; if not, it does the second action.
๐ฏ Exam Tip: Ensure that the `if` and `else` blocks are properly indented and that the condition evaluates to a Boolean value to avoid errors.
Question 3. Using if..else..elif statement write a suitable program to display largest of 3 numbers.
Answer: This program takes three numbers as input from the user and then uses `if`, `elif`, and `else` statements to compare them and find out which one is the largest. Each condition checks if a specific number is greater than the other two.
`a = int (input ("Enter number 1"))`
`b = int (input (" Enter number 2"))`
`c = int (input (" Enter number 3"))`
`if a > b and a > c:`
` print ("A is greatest")`
`elif b > a and b > c:`
` print ("B is greatest")`
`else:`
` print ("C is greatest")`
This structure ensures that exactly one of the three numbers will be identified as the greatest.
In simple words: This code asks for three numbers. It then uses 'if', 'elif', and 'else' to compare them and print which one is the biggest.
๐ฏ Exam Tip: When comparing multiple conditions, `elif` is efficient as it only evaluates its condition if previous `if`/`elif` conditions were false, making the code clean and readable.
Question 4. Write the syntax of while loop.
Answer: The `while` loop in Python repeatedly executes a block of code as long as a given condition remains true. It is an entry-controlled loop, meaning the condition is checked before the loop body is executed even once. This makes it suitable for situations where the number of iterations is not known beforehand.
The syntax of a `while` loop in Python is:
`while < condition >:`
` statements block 1`
`[else:`
` statements block 2]`
The `else` block is optional and is executed once the condition becomes false. It is important to ensure that the condition eventually becomes false to avoid an infinite loop.
In simple words: The 'while' loop keeps running a set of commands as long as a condition is true. If you add an 'else' part, it runs only when the main condition finally becomes false.
๐ฏ Exam Tip: Always make sure there is a statement inside the `while` loop that will eventually cause the condition to become `False`, to prevent infinite loops.
Question 5. List the differences between break and continue statements.
Answer: The `break` and `continue` statements are both used to alter the normal flow of loops, but they do so in different ways:
| Break Statement | Continue Statement |
|---|---|
| Terminates the loop entirely. | Skips the current iteration of the loop. |
| Control flow moves to the statement immediately after the loop's body. | Control flow jumps to the next iteration, re-evaluating the loop's condition. |
| Exits the loop prematurely. | Allows the loop to continue with subsequent iterations. |
| Can transfer control out of a loop. | Cannot transfer control out of a loop; it only skips iterations. |
In simple words: 'Break' stops a loop completely and moves on. 'Continue' skips only the current turn of the loop and then goes to the next turn, keeping the loop running.
๐ฏ Exam Tip: Remember `break` is for exiting a loop, while `continue` is for skipping the rest of the current iteration and moving to the next one.
IV. Answer The Following Questions (5 Marks)
Question 1. Write a detail note on for loop
Answer: The `for` loop in Python is used to iterate over a sequence (like a list, tuple, string, or range) or other iterable objects. It is a very versatile and commonly used loop structure. The `for` loop is considered an entry-check loop, meaning the condition for iteration is checked at the beginning of each cycle. This makes it a very efficient way to handle known-number iterations.
The general syntax for a `for` loop in Python is:
`for counter_variable in sequence:`
` statements โ block 1`
`[else: # optional block statements โ block 2]`
Here, the `counter_variable` takes on each value from the `sequence` one by one. The `statements โ block 1` is executed for each value. The optional `else` block is executed once the loop finishes normally (i.e., not terminated by a `break` statement).
The `range()` function is often used to generate sequences of numbers for `for` loops. It can specify the initial, final, and increment values, providing fine control over iteration. For example, `range(1, 10, 2)` will generate numbers 1, 3, 5, 7, 9.
The syntax of `range()` follows:
`range (start, stop, [step])`
Where:
start - refers to the initial value
stop โ refers to the final value (the sequence stops *before* this value)
step โ refers to increment value (this is an optional part, default is 1).
An example of its use is:
`#Program to illustrate the use of for loop โ to print single digit even number`
`for i in range (2,10,2):`
` print (i, end=" ")`
`Output:`
`2 4 6 8`
This demonstrates how the `for` loop, especially with `range()`, helps perform repetitive tasks effectively.
In simple words: The 'for' loop helps to do something for each item in a list or for a certain number of times. You can use `range()` with it to count numbers in a specific way, like from 1 to 10 by twos.
๐ฏ Exam Tip: When explaining `for` loops, always include the syntax, explain the role of the `sequence` and `counter_variable`, and mention the common use of `range()` with examples.
Question 2. Write a detail note on if..else..elif statement with suitable example.
Answer: The `if..else..elif` statement is a powerful conditional control structure in Python that allows for checking multiple conditions sequentially. It provides a way to handle several possible outcomes based on various conditions, rather than just two (as with `if-else`). This makes programs more flexible and capable of handling complex decision-making scenarios.
When building a chain of `if` statements, the `elif` (short for "else if") clause is used instead of nesting many `if-else` statements. The conditions are checked from top to bottom. The first condition that evaluates to `True` will have its corresponding code block executed, and then the rest of the `elif` and `else` blocks are skipped.
The general syntax is:
`if < condition -1>:`
` statements-block 1`
`elif< condition -2>:`
` statements-block 2`
`else:`
` statements-block n`
Here, `condition -1` is tested first. If true, `statements-block 1` is executed. Otherwise, `condition -2` is checked, and so on. If all `if` and `elif` conditions are false, the `else` block (if present) is executed. There is no limit to the number of `elif` clauses, but the `else` clause, if used, must be placed at the end.
Consider an example program to assign grades based on average marks:
`# Program to illustrate the use of nested if statement`
`# Average - Grade`
`# >=80 and above A`
`# >=70 and above B`
`# >=60 and <70 C`
`# >=50 and <60 D`
`# Otherwise E`
`m1 = int(input("Enter mark in first subject:"))`
`m2 = int(input(" Enter mark in second subject:"))`
`avg = (m1+m2)/2`
`if avg >=80:`
` print ("Grade: A")`
`elif avg >=70 and avg < 80:`
` print ("Grade: B")`
`elif avg >=60 and avg < 60:`
` print ("Grade: C")`
`elif avg >=50 and avg < 60:`
` print ("Grade: D")`
`else:`
` print("Grade: Eโ)`
This program efficiently determines the grade by checking conditions one after another until a match is found. This avoids complex nesting and makes the code very readable.
In simple words: The 'if-elif-else' statements help programs check many different choices one by one. If the first choice is true, it does that task. If not, it checks the next choice, and so on. If none are true, it does the 'else' task.
๐ฏ Exam Tip: Always remember the order of evaluation: `if` first, then `elif`s in sequence, and finally `else` if none of the preceding conditions were met. Proper indentation is critical.
Question 3. Write a program to display all 3 digit odd numbers.
Answer: This Python program uses a `for` loop and an `if` statement to find and display all odd numbers that have exactly three digits. Three-digit numbers range from 100 to 999. The program checks each number in this range to see if it is odd (i.e., its remainder when divided by 2 is 1).
`# Odd Number (3 digits)`
`for a in range (100, 1000):`
` if a % 2 == 1:`
` print(a)`
`Output:`
`101`
`103`
`105`
`107`
`...`
`997`
`999`
This code effectively filters the numbers, printing only those that meet the criteria.
In simple words: This program looks at all numbers from 100 to 999. If a number cannot be divided evenly by 2 (meaning it's odd), the program prints it.
๐ฏ Exam Tip: For problems involving number ranges, `range(start, stop)` is ideal. To check for odd/even, use the modulo operator (`%`).
Question 4. Write a program to display multiplication table for a given number.
Answer: This Python program asks the user for a number and then generates and displays its multiplication table up to 10 times. It uses a `for` loop to iterate from 1 to 10 and calculates each product.
`Coding:`
`num=int(input("Display Multiplication Table of "))`
`for i in range(1,11):`
` print(i, "x", num, '=', i*num)`
`Output:`
`Display Multiplication Table of 2`
`1 x 2 = 2`
`2 x 2 = 4`
`3 x 2 = 6`
`4 x 2 = 8`
`5 x 2 = 10`
`6 x 2 = 12`
`7 x 2 = 14`
`8 x 2 = 16`
`9 x 2 = 18`
`10 x 2 = 20`
The program clearly shows the products in a readable format.
In simple words: This program asks for a number. Then, using a loop, it multiplies that number by 1, then by 2, and so on, all the way up to 10, printing each answer like a multiplication table.
๐ฏ Exam Tip: When printing multiplication tables, ensure the loop iterates correctly (e.g., up to 10 or 12) and the output format is clear (e.g., "i x num = product").
12th Computer Science Guide Control Structures Additional Questions And Answers
I. Choose The Best Answer (1 Mark)
Question 1. Executing a set of statements multiple times are called................................
(a) Iteration
(b) Looping
(c) Branching
(d) Both a and b
Answer: (d) Both a and b
In simple words: When a computer program repeats a set of instructions many times, this action is called either iteration or looping. These terms essentially mean the same thing in programming.
๐ฏ Exam Tip: Remember that "iteration" and "looping" are interchangeable terms describing the process of repeating a block of code.
Question 2. ............ important control structures are available in python.
(a) 2
(b) 3
(c) 4
(d) Many
Answer: (b) 3
In simple words: Python has three main ways to control the order of a program: sequential (steps one after another), selection (making choices), and iteration (repeating actions).
๐ฏ Exam Tip: The three core control structures in programming are sequential, selection (conditional), and iteration (looping).
Question 3. Identify which is not a control structure?
(a) Sequential
(b) Alternative
(c) Iterative
(d) Break
Answer: (d) Break
In simple words: Break is a keyword used to exit loops, but it is not a type of control structure itself like sequential, alternative (if/else), or iterative (loops).
๐ฏ Exam Tip: Remember that "break", "continue", and "pass" are jump statements, not types of control structures. Control structures define the flow of execution, while jump statements alter that flow within existing structures.
Question 4. To construct a chain of if statement, else can be replaced by
(a) while
(b) ifel
(c) else if
(d) elif
Answer: (d) elif
In simple words: When you have many conditions to check one after another, instead of writing many 'if-else' statements, you can use 'elif', which is short for 'else if'.
๐ฏ Exam Tip: Using `elif` is more efficient than nested `if-else` statements because it avoids re-evaluating conditions once a true condition is found.
Question 5. Branching statements are otherwise called...
(a) Alternative
(b) Iterative
(c) Loop
(d) Sequential
Answer: (a) Alternative
In simple words: Branching statements let your program choose between different paths or options, which is why they are also called alternative statements.
๐ฏ Exam Tip: Branching statements (like `if`, `if-else`, `if-elif-else`) allow programs to make decisions and execute different code blocks based on conditions, offering "alternative" paths of execution.
Question 6. Which statement is used to skip the remaining part of a loop and start with the next iteration?
(a) continue
(b) break
(c) pass
(d) condition
Answer: (a) continue
In simple words: The 'continue' statement tells the program to stop the current round of the loop and immediately move to the next round, without finishing the rest of the code in the current round.
๐ฏ Exam Tip: Differentiate `continue` from `break`: `continue` skips the *current iteration* and proceeds to the next, while `break` *exits* the entire loop.
Question 7. In the ............... loop, the condition is any valid Boolean expression returning True or false.
(a) if
(b) else
(c) elif
(d) while
Answer: (d) while
In simple words: The 'while' loop keeps running as long as its condition stays true, and this condition must be something that can be either true or false.
๐ฏ Exam Tip: The condition in a `while` loop is checked *before* each iteration; if it's false from the start, the loop body never executes.
Question 8. How many blocks can be given in Nested if.. elif.. else statements?
(a) 1
(b) 2
(c) 3
(d) n
Answer: (d) n
In simple words: In Python, you can have as many 'elif' blocks as you need within an 'if-elif-else' structure, allowing for many different conditions.
๐ฏ Exam Tip: While there's no technical limit, using too many `elif` blocks can make code hard to read; consider functions or dictionaries for very complex conditional logic.
Question 9. A loop placed within another loop is called as ............. loop structure.
(a) entry check
(b) exit check
(c) nested
(d) conditional
Answer: (c) nested
In simple words: When one loop is put inside another loop, it is known as a nested loop, where the inner loop completes all its cycles for each cycle of the outer loop.
๐ฏ Exam Tip: Nested loops are commonly used for tasks like processing 2D arrays, generating patterns, or iterating through combinations of items.
Question 10. What types of Expressions can be given in the while loop?
(a) Arithmetic
(b) Logical
(c) Relational
(d) Boolean
Answer: (d) Boolean
In simple words: The 'while' loop needs a condition that is either true or false (a Boolean expression) to decide whether to keep running or stop.
๐ฏ Exam Tip: While arithmetic, logical, and relational expressions can form parts of a Boolean expression, ultimately the `while` loop requires the *result* of the expression to be a Boolean (True or False).
II. Answer the following questions (2 and 3 Marks)
Question 1. Write a note on sequential statements?
Answer: A sequential statement is simply a set of instructions that are executed one after another in the order they appear. There is no jumping or repeating; the program just moves from one line to the next. For example, a code that prints your name, address, and phone number in sequence is a type of sequential statement.
In simple words: Sequential statements are lines of code that run one by one from top to bottom, without skipping any or repeating any.
๐ฏ Exam Tip: Sequential execution is the default flow in most programming languages; understanding it is fundamental before moving to more complex control structures.
Question 2. Write the syntax of for loop.
Answer: The `for` loop in Python uses a specific structure to iterate over a sequence of items. Here is its syntax:
Syntax:
`for counter_variable in sequence:`
`statements-block 1`
`[else: # optional block`
`statement-block 2]`
Here, the `counter_variable` takes on each value from the `sequence` one by one, and `statements-block 1` runs for each value. The optional `else` block runs only if the loop finishes without being stopped by a `break` statement.
In simple words: The `for` loop syntax shows how to write a loop that goes through each item in a list or sequence, running a block of code for every item.
๐ฏ Exam Tip: The `else` block of a `for` loop is often overlooked but is useful for situations where you need to confirm that a loop completed all its iterations without interruption.
Question 3. Define loops?
Answer: Loops are programming tools that allow a specific block of code to be executed repeatedly. This is useful when a user needs to run the same code multiple times, either for a fixed number of repetitions or until a certain condition is met. Loops help automate repetitive tasks, making programs more efficient. For example, a loop can print numbers from 1 to 100 without writing 100 print statements.
In simple words: Loops let a computer program run the same set of instructions many times, either for a certain count or until a specific condition becomes true.
๐ฏ Exam Tip: Emphasize that loops are crucial for automating repetitive tasks and are a cornerstone of efficient programming in any language.
Question 4. What is meant by Nested loop structure?
Answer:
A nested loop structure is when one loop is placed entirely inside another loop. The inner loop completes all its iterations for each single iteration of the outer loop. This structure is commonly used when processing multi-dimensional data, like tables or grids.
- A loop placed within another loop is called a nested loop structure.
- Examples include a `while` loop inside another `while` loop, or a `for` loop inside another `for` loop.
- It can also be a `for` loop inside a `while` loop, or a `while` loop inside a `for` loop, to create various complex looping patterns.
In simple words: A nested loop means having one loop running inside another loop. The inside loop will run fully every time the outside loop takes one step.
๐ฏ Exam Tip: When tracing nested loops, remember that the inner loop must complete all its cycles for every single cycle of the outer loop.
Question 5. Give the syntax of range () in for loop?
Answer: The `range()` function is often used with `for` loops in Python to generate a sequence of numbers. Its syntax is quite flexible:
The syntax of `range()` follows:
`range (start, stop, [step])`
Where,
`start` - refers to the initial value (the first number in the sequence).
`stop` โ refers to the final value (the sequence stops *before* this number).
`step` โ refers to the increment value (how much to add each time), and this is an optional part. If `step` is not given, it defaults to 1. If `start` is not given, it defaults to 0.
In simple words: The `range()` function makes a list of numbers for a `for` loop. You can tell it where to start, where to stop (but not include that last number), and how much to jump by each time.
๐ฏ Exam Tip: A crucial point about `range()` is that the `stop` value is *exclusive*, meaning the sequence generated will always go up to, but not include, the `stop` number.
Question 6. Write a note on the pass statement.
Answer:
The `pass` statement in Python is a null operation; it does nothing when executed. It's simply a placeholder and is entirely ignored by the interpreter. Nothing at all happens when `pass` is run, meaning it results in no change or action. This is particularly useful when syntax requires a block of code, but you want to leave it empty for now, perhaps because you plan to implement it later.
- A `pass` statement in Python programming is a null statement.
- When executed by the interpreter, it is completely ignored.
- Nothing happens when the `pass` is executed, it results in no operation.
In simple words: The 'pass' statement in Python means "do nothing". It's like a placeholder you use when the computer expects some code, but you don't want anything to happen yet.
๐ฏ Exam Tip: `pass` is essential for creating empty classes, functions, or loop bodies to avoid syntax errors while you are still designing your program structure.
III. Answer the following questions (5 Marks)
Question 1. Explain the types of alternative or branching statements provided by Python?
Answer: Python provides several types of alternative or branching statements that allow a program to make decisions and execute different blocks of code based on certain conditions. These statements help control the flow of execution in a program. The main types are:
The types of alternative or branching statements provided by Python are:
1) Simple `if` statement
2) `if..else` statement
3) `if..elif` statement
1) Simple `if` statement
The simple `if` statement is the most basic decision-making statement. It checks a condition, and if that condition is true, a specific block of code is executed. The condition must be a relational or logical expression that evaluates to `True` or `False`.
Syntax:
`if condition:`
`statements-block1`
Example:
`x=int (input("Enter your age :"))`
`if x >= 18:`
`print ("You are eligible for voting")`
Output:
`Enter your age :34`
`You are eligible for voting`
In this example, if the age is 18 or more, the message "You are eligible for voting" is displayed. If the age is less than 18, the program continues without printing this message.
2) `if..else` statement
The `if..else` statement provides two possible paths of execution. It checks a condition: if the condition is true, one block of code (the `if` block) is executed; otherwise, a different block of code (the `else` block) is executed. This ensures that one of the two blocks will always run.
Syntax:
`if condition:`
`statements-block 1`
`else:`
`statements-block 2`
Example:
`a = int(input(" Enter any number :"))`
`if a%2==0:`
`print (a," is an even number")`
`else:`
`print (a, " is an odd number")`
Output 1:
`Enter any number:56`
`56 is an even number`
Output 2:
`Enter any number:67`
`67 is an odd number`
This program checks if a number is even or odd, executing the appropriate print statement. The flowchart for `if..else` execution visually demonstrates this two-path decision.
The flowchart for if..else statement execution:
3) Nested `if..elif...else` statement:
This structure is used when there are multiple conditions to check, creating a chain of decisions. The `elif` (short for "else if") clause allows you to test several conditions in order. If a condition is true, its block is executed, and the rest of the `elif` and `else` blocks are skipped. If no `if` or `elif` condition is met, the final `else` block (if present) is executed.
- When we need to construct a chain of `if` statement(s), then the `elif` clause can be used instead of `else`.
- The `elif` clause combines `if..else-if..else` statements into one `if..elif...else` structure. `elif` can be considered an abbreviation of 'else if'.
- In an `if` statement, there is no limit to how many `elif` clauses can be used, but an `else` clause (if used) should always be placed at the very end.
Syntax:
`if
`statements-block 1`
`elif
`statements-block 2`
`else:`
`statements-block n`
In this structure, condition -1 is tested; if it's true, `statements-block 1` is executed. Otherwise, the control checks condition -2, and so on. If all conditions fail, `statements-block n` (in the `else` part) is executed.
Example:
This program illustrates how to use `if-elif-else` to assign grades based on an average score.
`# Program to illustrate the use of nested if statement`
`Average - Grade`
`>=80 and above A`
`>=70 and above B`
`>=60 and <70 C`
`>=50 and <60 D`
`Otherwise E`
Example-program
`m1 = int(input("Enter mark in first subject:"))`
`m2 = int(input(" Enter mark in second subject:"))`
`avg = (m1+m2)/2`
`if avg >=80:`
`print ("Grade: A")`
`elif avg >=70 and avg < 80:`
`print ("Grade: B")`
`elif avg >=60 and avg < 70:`
`print ("Grade: C")`
`elif avg >=50 and avg < 60:`
`print ("Grade: D")`
`else:`
`print("Grade: Eโ)`
Output 1:
`Enter mark in first`
`subject: 34`
`Enter mark in second`
`subject: 78`
`Grade: D`
In simple words: Python has three main ways to make choices in a program: a simple 'if' for one condition, 'if-else' for two choices, and 'if-elif-else' for many choices. This helps the program decide which code to run based on different situations.
๐ฏ Exam Tip: Always place the most specific or critical conditions first in an `if-elif-else` chain, as conditions are evaluated in order and only the first `True` block executes.
Question 2. Explain while loop with example.
Answer: A `while` loop repeatedly executes a block of code as long as a given condition remains true. It is an "entry-check" loop, meaning the condition is evaluated at the beginning of each iteration. If the condition is false initially, the loop body will not execute even once. This makes it suitable for situations where the number of repetitions is unknown beforehand, and depends on some dynamic condition.
- A `while` loop belongs to the entry-check loop type, meaning it is not executed even once if the condition is tested false in the beginning.
- In the `while` loop, the condition must be any valid Boolean expression, which means it returns `True` or `False`.
- The `else` part of a `while` loop is optional. The statements within the main `while` block are executed repeatedly as long as the condition is `True`.
- If the `else` part is included, it is executed only when the `while` loop's condition becomes `False`, and the loop finishes normally (not by a `break` statement).
Syntax:
`while
`statements block 1`
`[else:`
`statements block 2]`
Flowchart-while loop execution:
Example:
| Code | Explanation |
|---|---|
| `i=10` | # initializing part of the control variable |
| `while (i<=15):` | # test condition |
| `print (i,end='\t')` | # statements โ block1 |
| `i=i+1` | # Updation of the control variable |
This example initializes `i` to 10. The `while` loop continues as long as `i` is less than or equal to 15. Inside the loop, `i` is printed, and then `i` is increased by 1. The loop will print 10, 11, 12, 13, 14, 15.
In simple words: A `while` loop keeps running a block of code again and again as long as its condition is true. If the condition starts false, it won't run even once.
๐ฏ Exam Tip: Always ensure there is a statement inside a `while` loop that can eventually make its condition false, otherwise, you will create an infinite loop.
Question 3. Explain the Jump statement in python.
Answer: Jump statements are used in Python to unconditionally transfer the control flow of a program from one part of the code to another. These statements alter the normal, sequential execution of a program, allowing for more dynamic control over loops and function calls. Python includes three primary jump statements: `break`, `continue`, and `pass`.
- There are three keywords to achieve jump statements in Python: `break`, `continue`, `pass`.
Flowchart -Use of break, continue statement in loop structure:
**`break` statement:**
- The `break` statement immediately stops the loop that contains it.
- When `break` is executed, the program's control jumps to the statement right after the loop's entire body.
- If `break` is inside a nested loop (a loop within another loop), it only terminates the innermost loop, not any outer loops.
Syntax for `break` statement: `break`
Example: for word in "Jump Statement":
`if word == "e":`
`break`
`print (word, end=" ")`
Output: `Jum p Stat`
Flowchart- Working of break statement:
**`continue` statement:**
The `continue` statement is different from `break`; it is used to skip the remaining part of the current iteration of a loop and immediately move to the next iteration. The loop does not terminate entirely, but the current cycle is cut short.
Syntax for `continue` statement: `continue`
Example for `continue`:
`for word in "Jump Statement":`
`if word == "e":`
`continue`
`print (word, end="")`
`print ("\n End of the program")`
Output:
`Jum p Stat`
`End of the program`
**`pass` statement:**
- The `pass` statement is generally used as a placeholder.
- When we have a loop or function that needs to be implemented in the future but not now, we cannot leave its body empty due to syntax requirements; otherwise, the interpreter would raise an error.
- So, to avoid this, we can use a `pass` statement to create a body that does nothing.
Syntax of `pass` statement: `pass`
Example:
`for val in "Computer":`
`pass`
`print ("End of the loop, loop structure will be built in future")`
Output: `End of the loop, loop structure will be built in future`
In simple words: Jump statements like `break`, `continue`, and `pass` change how a program normally flows. `break` stops a loop completely, `continue` skips to the next round of a loop, and `pass` acts as a placeholder when you want to write code later.
๐ฏ Exam Tip: Remember `break` and `continue` specifically relate to loops, while `pass` can be used in any block where a statement is syntactically required but no action is needed yet.
Question 4. (This question appears to be cut off in the source, only mentioning "Can be created?")
Answer: Given the incomplete question, it's difficult to provide a specific answer. However, if the question was related to creating new control structures or combining existing ones, Python allows for flexible logic using its standard control flow statements. For instance, complex decision-making or looping patterns can be created by nesting `if` statements within `for` loops, or `while` loops within functions. The combination of these basic building blocks enables the construction of highly sophisticated program logic.
In simple words: Since the question is cut off, it's hard to answer exactly. But in programming, you can always build complex things by putting together simple commands and structures.
๐ฏ Exam Tip: In an exam, if a question is ambiguous or incomplete, state your interpretation of the question and answer based on that, or explain why it's not fully answerable as given.
Question 1. Write a program to check whether the given character is a vowel or not.
Answer: To check if a character is a vowel, we can write a Python program that takes a character as input and then checks if it is present in a list of both lowercase and uppercase vowels.
Coding:
`ch=input ("Enter a character :")`
`# to check if the letter is vowel`
`if ch in ('a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U'):`
`print (ch, " is a vowel")`
`else:`
`print (ch, " is not a vowel")`
Output:
`Enter a character:e`
`e is a vowel`
In simple words: This program asks for a letter and then checks if that letter is one of the vowels (a, e, i, o, u, or their capital versions). It will then tell you if it's a vowel or not.
๐ฏ Exam Tip: Remember to check for both lowercase and uppercase vowels when writing such a program to make it robust and user-friendly.
Question 2.
(i) Write a program to display all 3 digit even numbers.
(ii) Write the output for the following program.
Answer:
(i) Python Program to display all 3 digit even numbers:
To display all 3-digit even numbers, we can use a `for` loop that iterates from 100 to 999 (inclusive of 100, exclusive of 1000) with a step of 2, since every second number will be even.
`for i in range(100, 1000, 2):`
`print(i)`
This program will directly print all even numbers starting from 100 up to 998, as `range(start, stop, step)` generates numbers from `start` up to (but not including) `stop`, incrementing by `step`.
Output:
`100`
`102`
`104`
...
`998`
(ii) Output for the following program:
The given program is:
`i=1`
`while (i<=6):`
`for j in range (1, i):`
`print(j, end='\t')`
`print (end=' \n')`
`i+=1`
This program uses a nested loop structure. The outer `while` loop runs as long as `i` is less than or equal to 6. The inner `for` loop prints numbers from 1 up to `i` for each iteration of the outer loop.
When \( i = 1 \): Inner loop `range(1, 1)` is empty. Prints a newline.
When \( i = 2 \): Inner loop `range(1, 2)` prints `1`. Prints a newline.
When \( i = 3 \): Inner loop `range(1, 3)` prints `1 2`. Prints a newline.
When \( i = 4 \): Inner loop `range(1, 4)` prints `1 2 3`. Prints a newline.
When \( i = 5 \): Inner loop `range(1, 5)` prints `1 2 3 4`. Prints a newline.
When \( i = 6 \): Inner loop `range(1, 6)` prints `1 2 3 4 5`. Prints a newline.
Output:
(empty line for i=1)
`1`
`1 2`
`1 2 3`
`1 2 3 4`
`1 2 3 4 5`
In simple words: The first part of the answer shows how to print all even numbers that have three digits. The second part explains what will be shown on the screen when the given code runs, which is a pattern of increasing numbers on new lines.
๐ฏ Exam Tip: When dealing with `range()` functions, always remember that the `stop` value is exclusive. For nested loops, mentally trace each iteration of the outer loop and then the complete execution of the inner loop for precise output prediction.
Question 3. Write a program to check if a number is Positive, Negative or zero.
Answer:
Coding:
num = float(input(" Enter a number: "))
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
Output:
Enter a number:5
Positive number
In simple words: This program asks you for a number. Then it checks if the number is bigger than zero (positive), exactly zero, or smaller than zero (negative). It tells you which one it is.
๐ฏ Exam Tip: Remember to use `float(input())` if you want to allow decimal numbers, otherwise `int(input())` is enough for whole numbers.
Question 4. Write a program to display Fibonacci series 0112345 (up to n terms)
Answer:
Coding:
Number = int(input("\n Please Enter the Range Number: "))
i = 0
First_Value = 0
Second-Value = 1
while(i < Number):
print(First_Value)
Next = First-Value + Second_Value
First_Value = Second_Value
Second_Value = Next
i = i + 1
Output:
Please Enter the Range Number: 4
0
1
1
2
In simple words: This program creates a Fibonacci series. It starts with 0 and 1, then each new number is the sum of the two before it. You tell it how many numbers to show.
๐ฏ Exam Tip: The Fibonacci sequence is created by adding the two previous numbers. Ensure your loop correctly updates `First_Value` and `Second_Value` in each iteration.
Question 5. Write a program to display sum of natural numbers, up to n.
Answer:
Coding:
number = int(input("Please Enter any Number:"))
total = 0
for value in range(1, number + 1):
total = total + value
print("The Sum of Natural Numbers is", total)
Output:
Please Enter any Number:5
The Sum of Natural Numbers is : 15
In simple words: This program takes a number from you, like 5. Then it adds up all the numbers from 1 to 5 (1+2+3+4+5) and shows you the total.
๐ฏ Exam Tip: The `range(1, number + 1)` is crucial here to include the `number` itself in the sum, as `range` usually stops one before the end value.
Question 6. Write a program to check if a number is a palindrome or not.
Answer:
Coding:
n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")
Output:
isn't a palindrome!
In simple words: This program asks for a number, then checks if it reads the same forwards and backwards. If it does, it's a palindrome, like 121. If not, it says it isn't.
๐ฏ Exam Tip: To check for a palindrome, you need to reverse the number and then compare it with the original number. Store the original number in a temporary variable before reversing.
Question 7. Write a program to print the following pattern
*****
****
***
**
*
Answer:
Coding:
number = int(input("Please Enter Pattern Number: "))
for i in range(number,0,-1):
for j in range(1,i+1,1):
print("*", end=" ")
print()
In simple words: This program draws a star pattern that gets smaller with each line. You tell it how many rows of stars you want, and it makes a triangle shape.
๐ฏ Exam Tip: Nested loops are typically used for printing patterns. The outer loop controls the number of rows, and the inner loop controls what is printed in each row.
Question 8. Write a program to check if the year is leap year or not.
Answer:
Coding:
def leap_year(y):
if (y % 400 == 0):
print(y, "is the leap year")
elif(y % 4 == 0):
print(y, "is the leap year")
else:
print(y, "is not a leap year")
year = int(input("Enter a year..."))
print(leap_year(year))
Output:
Enter a year... 2007
2007 is the leap year
In simple words: This program asks for a year and then figures out if it's a leap year or not. A leap year happens almost every four years to add an extra day to February.
๐ฏ Exam Tip: Remember the rules for a leap year: it must be divisible by 4, but not by 100, unless it is also divisible by 400. Check these conditions in that specific order.
Free study material for Computer Science
TN Board Solutions Class 12 Computer Science Chapter 06 Control Structures
Students can now access the TN Board Solutions for Chapter 06 Control Structures prepared by teachers on our website. These solutions cover all questions in exercise in your Class 12 Computer Science textbook. Each answer is updated based on the current academic session as per the latest TN Board syllabus.
Detailed Explanations for Chapter 06 Control Structures
Our expert teachers have provided step-by-step explanations for all the difficult questions in the Class 12 Computer Science chapter. Along with the final answers, we have also explained the concept behind it to help you build stronger understanding of each topic. This will be really helpful for Class 12 students who want to understand both theoretical and practical questions. By studying these TN Board Questions and Answers your basic concepts will improve a lot.
Benefits of using Computer Science Class 12 Solved Papers
Using our Computer Science solutions regularly students will be able to improve their logical thinking and problem-solving speed. These Class 12 solutions are a guide for self-study and homework assistance. Along with the chapter-wise solutions, you should also refer to our Revision Notes and Sample Papers for Chapter 06 Control Structures to get a complete preparation experience.
FAQs
The complete and updated Samacheer Kalvi Class 12 Computer Science Solutions Chapter 6 Control Structures is available for free on StudiesToday.com. These solutions for Class 12 Computer Science are as per latest TN Board curriculum.
Yes, our experts have revised the Samacheer Kalvi Class 12 Computer Science Solutions Chapter 6 Control Structures as per 2026 exam pattern. All textbook exercises have been solved and have added explanation about how the Computer Science concepts are applied in case-study and assertion-reasoning questions.
Toppers recommend using TN Board language because TN Board marking schemes are strictly based on textbook definitions. Our Samacheer Kalvi Class 12 Computer Science Solutions Chapter 6 Control Structures will help students to get full marks in the theory paper.
Yes, we provide bilingual support for Class 12 Computer Science. You can access Samacheer Kalvi Class 12 Computer Science Solutions Chapter 6 Control Structures in both English and Hindi medium.
Yes, you can download the entire Samacheer Kalvi Class 12 Computer Science Solutions Chapter 6 Control Structures in printable PDF format for offline study on any device.