Page 108 - Trackpad_V5_Book 8
P. 108

Program 2: To check whether the entered number is even or odd.














            You will get the following output:





















            THE if-elif-else STATEMENT
            Sometimes, we need to evaluate multiple statements to get a certain result. In such scenarios, we
            can use the if-elif-else statements to evaluate multiple scenarios. First, it checks and evaluates
            the  first  condition.  If it  is  true,  it  will
                                                                 Test
            execute  the respective  statement(s),            expression    True   Statement 1
            but  if the condition  is false,  it  goes            1
            to  the  elif  statement  and  evaluated                False
            those  conditions.  Finally, if none of the
                                                                 Test       True
            conditions evaluates to true it executes                               Statement 2
                                                              expression
            the else block. The syntax of if-elif-else            2
            statement is as follows:                                False

                if (conditional expression):
                                                                 Test       True
                        statement(s)                          expression           Statement 3
                                                                  3
                elif (conditional expression):
                                                                    False
                        statement(s)
                                                                                   Body of else
                elif (conditional expression):

                        statement(s)                                                               Statement just
                                                                                                   below if-elseif
                else:

                        statement(s)






            106   Pro (Ver. 5.0)-VIII
   103   104   105   106   107   108   109   110   111   112   113