Page 511 - ComputerScience_Class_11
P. 511

6.  Explain the rules for using indentation in Python.
                   Ans.  The rules for indentation in Python are:
                        •  Use 4 spaces for indentation as recommended by PEP 8 guidelines.
                        •  Use either spaces or tabs consistently, but never mix both.
                        •  All statements inside the same block must have equal indentation.
                        •  The first line after control structures or function definitions must be indented.
                        •  Nested blocks require additional indentation levels.
                    7.  Differentiate between fixed iteration and unfixed iteration.
                   Ans.  The difference between fixed and unfixed iteration is shown in Table:

                                    Fixed Iteration                       Unfixed Iteration
                       Number of repetitions known            Number not known Beforehand
                       Uses for loop                          Uses while loop
                       Controlled by sequence or range        Controlled by condition
                       Definite iteration                     Indefinite iteration

                    8.  How does flow of control allow a program to make decisions and repeat actions?
                   Ans.  Flow of control allows decision-making using conditional statements like if, elif and else. These statements evaluate conditions
                       and execute code accordingly. Repetition is achieved using loops such as for and while, which execute a block of code multiple
                       times based on a condition or sequence. This capability makes programs interactive and responsive to different inputs.

                 D.  Higher Order Thinking Skills (HOTS)
                    1.  A student writes a program to check whether a number is positive. However, the program prints nothing when the number is
                       negative. Which flow of control concept is missing and why?
                   Ans.  The program lacks an else statement. The if condition executes only when the number is positive, so negative values are ignored.
                       Adding an else block ensures an alternative action executes, enabling proper decision-making and complete handling of all
                       possible inputs.
                    2.  An online shopping app gives discounts based on customer categories: Student, Member or Guest. Which conditional structure
                       is most suitable and why?
                   Ans.   An if-elif-else structure is most suitable because multiple mutually exclusive conditions must be evaluated. The program checks
                       each category sequentially and executes only one matching block, ensuring correct discount assignment without unnecessary or
                       repeated condition evaluations.
                 E.  Assertion and reasoning questions.
                     The  following  questions  consist  of  two  statements  –  Assertion  (A)  and  Reason  (R).  Answer  these  questions  by  selecting  the
                     appropriate option given below:
                     a.  Both A and R are true and R is the correct explanation of A.
                     b.  Both A and R are true but R is not the correct explanation of A.
                     c.  A is true but R is false.
                     d.  A is false but R is true.
                    1.  Assertion (A): Flow of control determines the order in which program statements are executed.
                       Reason (R): It allows decision-making, looping and branching in programs.
                   Ans.  a.  Both A and R are true and R is the correct explanation of A.
                    2.  Assertion (A): Sequential flow of control involves decision-making and repetition.
                       Reason (R): Sequential flow executes statements one after another without branching.
                   Ans.  d.  A is false but R is true.
                    3.  Assertion (A): A for loop is generally used when the number of iterations is known beforehand.
                       Reason (R): It often works with sequences such as range, list or string.
                   Ans.  b.  Both A and R are true but R is not the correct explanation of A.




                                                                                                    Flow of Control  509
   506   507   508   509   510   511   512   513   514   515   516