Page 210 - Computer Science Class 11 With Functions
P. 210

l  itlnoSlnSlShtltnetlindtnSntonlatvtalntlShtltSnStetnSl
        l      print("Number is EVEN")

        l  IntStnd,liSlitlnSlnlatvtalnSlwhichlShtlhtndtrl
        l      if num%2 == 0:
        l  l npptnrt.lThtrtfort,liSlitlnoSlpnrSloflShtlif-baocklnndlitltxtcuStdlirrttptctvtloflwhtShtrlShtlconditonnaltxprtttionl
           (num%2 == 0)lyitadtlTrue or False. ThtrtlitlnolaieiSlonlShtlnuebtrlofltSnStetnStlShnSlcnnlbtlincaudtdlinl
           Shtlif baock.lContidtrlShtlfoaaowinglcodtlShnSlincaudttlSwoltSnStetnStlinlShtlif-baock.
        l  num = int(input("Enter a number : "))
        l  if num%2 == 0:

              print("Number is EVEN")
              print("Division by 2 leaves the remainder Zero")
        l  print("Divisibility Check Done")


               The conditional expression may not include the use of relational operators. Consider the following examples:

                   x = 10
                   if x:
                       print("Condition is True")
               Condition is True          # if block is executed
               In Python, any non-zero value (other than None) is considered to be Boolean True. In the above example, as the
               value of x is 10, the Boolean expression x yields True. Therefore, the conditional expression of the if statement
               yields True
                   if None:
                       print("Condition is not True") # if block isn't executed
               In the above example, the conditional expression None yields False. Therefore, the if-block following the
               condition None:
               print("Condition is True") is ignored by the Python interpreter.



        9.3.2 if-else Statement

        Thtl ifl tSnStetnSl txtcuSttl nl ttqutnctl ofl tSnStetnStl whtnl Shtl conditonnal txprtttionl yitadtl True.l Thtl ifl
        tSnStetnSlitlignortdlbylShtlPyShonlinStrprtStrlwhtnlShtlconditonnaltxprtttionlyitadtlFalse.lHowtvtr,ltoettett,l
        ctrSninltSnStetnStlnttdlSolbtltxtcuStdlwhtnlShtlconditonnaltxprtttionlitlFalse. InltuchlnltiSunton,lnn else
        canuttlitluttd.

         ynSnx:
        if <conditional expression>:ll             lllllllllllllllllllllllllllllllllllllllllll……..htndtr
        llllllllllll <sequence S1 of statement(s)>llllllllllllllll…….lif tuiStl/lbaock

        else:
        lllllllllll <sequence S2 of statement(s)>l         llllllll…...lelseltuiStl/lbaockl












         208   Touchpad Computer Science-XI
   205   206   207   208   209   210   211   212   213   214   215