Page 42 - 2501_KVS_C-8
P. 42

This can easily be understood by the following example:
                  Let us say we need to make a program in python to check the age of a student between
                  13 and 15 and if both these conditions are True, then the value of a CLASS variable will

                  be 8, otherwise a message should be displayed “CLASS NOT KNOWN”. This can well be
                  understood by the following code in python:

                                            Age = 14


                                            if Age >= 13 and Age <= 15:
                                                    CLASS = 8
                                                    print("CLASS:", CLASS)
                                            else:
                                                    print("CLASS NOT KNOWN")

                      OR Operator: “or” operators work on two(02) or more than 02 conditions/expressions
                       and it will give the result True if any one of the two conditions is True. It will give the
                       result False, if both the two(02) conditions are False. In python, this operator is used
                       by the keyword “or”.

                       It can also be understood by the following table:

                                                  A                B             A or B
                                                  0                0                0
                                                  1                0                1
                                                  0                1                1
                                                  1                1                1

                  Here, the value of the final expression will be 1 or True if the value of any one of the
                  conditions A & B is 1 or True.
                  This can easily be understood by the following example:

                  Let us say we need to create a program in python to check the age of a student whether it
                  is greater than 13 or is smaller than 15 and the value of a CLASS variable will be 8 if any
                  one of the two conditions is 1 or True, otherwise a message should be displayed “CLASS
                  NOT KNOWN”. This can well be understood by the following code in python:

                                            Age=14



                                            if Age >= 13 or Age<=15:
                                                    print("class is 8")
                                                    CLASS=8
                                            else:
                                                    print("CLASS NOT KNOWN")






                40                         KVS DELHI REGION 2025
   37   38   39   40   41   42   43   44   45   46   47