Page 112 - TCS ICT Book 8
P. 112

The City School  2021-2022





             Logical operators are similar to Boolean expressions that return a boolean result.
             These operators are called binary because they acquire two operands.



                           Operator                             Meaning

                       AND                 Both sides must be true
                       OR                  One one the two conditions must be true

                       XOR                 One side or other must be true but not both
                       NOT                 Negates truth




             5.9.  Looping Statement in Python

             A For loop is used for repeating over a sequence (that is either a list or a string). This

             is less like the FOR keyword in other programming languages and works more like an
             iterator method as found in other object-orientated programming languages.

             For example, we have a list of students and we want to display the student with the
             highest marks without using the max() function:


             Sample code:


            # This defines a list of student marks
            stdMarks = [70, 80, 92.5, 60.2]
            # This variable keeps track of the max marks

            maxMarks = 0

            # for loop block
            for i in range(0,4):
                if stdMarks[i] > maxMarks:

                       maxMarks = stdMarks[i]

            # Prints highest student marks
            print(“Highest student marks are:”, maxMarks)
























                                                                                                                112
   107   108   109   110   111   112   113   114   115   116   117