Page 65 - Digicode_AI_class_8
P. 65

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.

            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

            if a>b:
                print (“a is greater than b”)
            elif a==b:

                print (“a is equal to b”)
            else:
                print (“a is less than b”)

            Explanation: In this, you are comparing the values of two variables by using a comparison operator.
            In the first statement it checks if a is greater than b, if this condition is true then it print (“a is
            greater than b”), and if the condition is false, then “elif” block will execute and checks if a is equal
            to b, if it is true, then it prints (“a is equal to b”) and if it is false then it print (“a is less than b”).





                                  Alan Turing, the father of modern computer
                              science was famous for developing the first modern
                                                   computer.



                                                                                 Information Literacy
                   code Quest                                                    Media Literacy


                   State whether the following statements are true (T) or false (F).

                   1.  Control structure is a basic decision-making process.
                   2.   Selection statement executes a set of statements for a certain
                       number of times.





                                                                           Advanced MakeCode Arcade       63
   60   61   62   63   64   65   66   67   68   69   70