Python Control Structures: book back answers

18 solved questions from the end of this chapter, Class 12 Computer Science, Tamil Nadu State Board. Each answer is checked against the textbook, and you can open the page that proves it.

← Notes and quiz for Python Control Structures

Choose the best answer 1 Marks

  1. How many important control structures are there in Python?

    • A) 3
    • B) 4
    • C) 5
    • D) 6
    Try it, then show the answer

    A) 3

    The chapter lists three important control structures: sequential, alternative or branching, and iterative or looping.

    From the book: “There are three important control structures”

  2. elif can be considered to be abbreviation of

    • A) nested if
    • B) if..else
    • C) else if
    • D) if..elif
    Try it, then show the answer

    C) else if

    The chapter states that ‘elif’ can be considered an abbreviation of ‘else if’.

    From the book: “‘elif’ can be considered to be abbreviation of ‘else if’.”

  3. What plays a vital role in Python programming?

    • A) Statements
    • B) Control
    • C) Structure
    • D) Indentation
    Try it, then show the answer

    D) Indentation

    Indentation is required to show which block of code a statement belongs to.

    From the book: “Indentation plays a vital role in Python programming”

  4. Which statement is generally used as a placeholder?

    • A) continue
    • B) break
    • C) pass
    • D) goto
    Try it, then show the answer

    C) pass

    The chapter describes pass as a placeholder for a block that is to be implemented later.

    From the book: “pass statement is generally used as a placeholder.”

  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
    Try it, then show the answer

    C) Relational or Logical expression

    The chapter says a simple if condition should be a relational or logical expression.

    From the book: “Condition should be in the form of relational or logical expression.”

  6. Which of the following is known as definite loop?

    • A) do..while
    • B) while
    • C) for
    • D) if..elif
    Try it, then show the answer

    C) for

    A for loop is known as a definite loop because the programmer knows how many times it will execute.

    From the book: “The for loop is usually known as a definite loop”

  7. What is the output of the following snippet? T=1 while T: print(True) break

    • A) False
    • B) True
    • C) 0
    • D) 1
    Try it, then show the answer

    B) True

    T is nonzero, so the loop runs, prints True, and then break terminates the loop.

    From the book: “When the break statement is executed, the control flow of the program comes out of the loop”

  8. Which amongst this is not a jump statement ?

    • A) for
    • B) pass
    • C) continue
    • D) break
    Try it, then show the answer

    A) for

    The chapter lists break, continue, and pass as jump statements. A for loop is a looping construct, not one of those jump statements.

    From the book: “There are three keywords to achieve jump statements in Python : break, continue, pass.”

  9. Which punctuation should be used in the blank? if <condition>_ statements-block 1 else: statements-block 2

    • A) ;
    • B) :
    • C) ::
    • D) !
    Try it, then show the answer

    B) :

    The syntax shown for if..else places a colon after the condition.

    From the book: “Syntax: if <condition>: statements-block 1 else: statements-block 2”

Part -II — Answer the following questions 2 Marks

  1. List the control structures in Python.

    Try it, then show the answer

    Sequential, alternative or branching, and iterative or looping.

    These are the three types of flow of control identified in the chapter.

    From the book: “Three types of flow of control are o Sequencing o Branching or Alternative o Iteration”

  2. Write note on break statement.

    Try it, then show the answer

    The break statement terminates the loop containing it and transfers control to the statement immediately after the loop. In a nested loop, it terminates the innermost loop.

    Break exits the loop rather than continuing its remaining iterations.

    From the book: “The break statement terminates the loop containing it.”

  3. Write is the syntax of if..else statement

    Try it, then show the answer

    if <condition>: statements-block 1 else: statements-block 2

    The condition determines whether the true block or the false block is executed.

    From the book: “The if .. else statement provides control to check the true block as well as the false block.”

  4. Define control structure.

    Try it, then show the answer

    A program statement that causes a jump of control from one part of the program to another is called a control structure or control statement.

    It changes the flow of control in a program.

    From the book: “A program statement that causes a jump of control from one part of the program to another is called control structure or control statement.”

  5. Write note on range () in loop

    Try it, then show the answer

    range() is a built-in function used to generate a series of values between numeric intervals. Its syntax is range(start, stop, [step]); the stop value is not included.

    The optional step specifies the increment, and the generated values run up to stop minus one.

    From the book: “The range() is a built-in function, to generate series of values between two numeric intervals.”

Part -III — Answer the following questions 3 Marks

  1. Write note on if..else structure.

    Try it, then show the answer

    The if..else statement checks a condition and provides two possible paths. If the condition is true, statements-block 1 is executed; otherwise, statements-block 2 is executed.

    The condition selects which of the two blocks will run.

    From the book: “if..else statement thus provides two possibilities and the condition determines which BLOCK is to be executed.”

  2. Write the syntax of while loop.

    Try it, then show the answer

    while <condition>: statements block 1 [else: statements block 2]

    The else part is optional and executes when the while condition becomes false.

    From the book: “while <condition>: statements block 1 [else: statements block2]”

  3. List the differences between break and continue statements.

    Try it, then show the answer

    break terminates the loop and transfers control to the statement after the loop. continue skips the remaining part of the current iteration and starts the next iteration.

    Break exits the loop; continue keeps the loop going but skips the rest of that iteration.

    From the book: “Continue statement unlike the break statement is used to skip the remaining part of a loop and start with next iteration.”

Part -IV — Answer the following questions 5 Marks

  1. Write a detail note on if..else..elif statement with suitable example.

    Try it, then show the answer

    The if..else..elif statement is an alternative or branching statement used to choose a block of code according to conditions. It allows a program to test a chain of conditions and execute the appropriate block.

    1. if..else statement: The if..else statement checks both the true and false possibilities. If the condition is true, statements-block 1 is executed; otherwise, statements-block 2 is executed.
    2. if..elif..else syntax: The if condition is tested first. If it is false, the elif condition is checked; if that also fails, the block under else is executed.
    3. Use of elif: The elif clause is used to form a chain of conditions and is an abbreviation of ‘else if’. There is no limit to the number of elif clauses; if used, else must be placed at the end.
    4. Execution order: Conditions are tested in order. The block belonging to the first true condition is executed; the remaining conditions and blocks are not selected.
    5. Indentation: Indentation shows which block a statement belongs to in Python. The if and elif statements in the example are indented four spaces.

    Example: Example 6.5 calculates the average of two subject marks and assigns a grade: avg>=80 gives A; avg>=70 and avg<80 gives B; avg>=60 and avg<70 gives C; avg>=50 and avg<60 gives D; otherwise it gives E.

    Thus, if..else..elif provides a clear way to choose and execute a code block based on conditions.

    From the book: “‘Multiple if..else statements can be combined to one if..elif…else.”

Next chapterPython Functions