Page 10 - Touchcode_C8_Flipbook
P. 10

IF-ELSE Statement
                  The above mentioned logic can be applied through if-else statement. The if-else statement

                  requires three things:
                      Evaluation statement: Condition or expression that is being checked.
                      Execution statement: Operations which will be performed if the condition appears to
                      be true.

                      Else execution block: Operation which will be performed only if the evaluation statement
                      is false.
                                                                                                          Subject Enrichment

                     Example: To check if a number is even or odd by using if-else statement.

                  Flowchart:                           Start




                                                      Read a
                                                     number




                                                  Is the number      No     The number is odd
                                                  divisible by 2?

                                                          Yes


                                                The number is even



                                                       End


                  Explanation: To implement this in a program, you will use, number%2=0, i.e., we divide the
                  number by 2 and if the remainder comes out to be 0, then the number is even, otherwise
                  the number is odd.


                  ELSE-IF Statement
                  Suppose you need to compare two numbers a, b and check if a is greater than b or they are
                  equal. To implement this, you need to check two conditions.

                  In python, the keyword elif, is used for checking another statement in case the previous

                  statement is false.
                  Code:

                  a=23
                  b=23




                    8     Touchcode-VIII
   5   6   7   8   9   10   11   12   13   14   15