Page 60 - Touhpad Ai
P. 60

print("Division Assignment:", x)
                 # Modulus assignment
                 x %= 3
                 print("Modulus Assignment:", x)
                 # Floor division assignment
                 x //= 2
                 print("Floor Division Assignment:", x)
                 # Exponentiation assignment

                 x **= 3
                 print("Exponentiation Assignment:", x)
                 Output:

                 Assignment: 15
                 Addition Assignment: 18
                 Subtraction Assignment: 16
                 Multiplication Assignment: 64
                 Division Assignment: 32.0

                 Modulus Assignment: 2.0
                 Floor Division Assignment: 1.0
                 Exponentiation Assignment: 1.0
              Logical Operators
              Logical operators are used to combine conditional statements. They return True or False depending on the conditions.
              Logical operators include AND, OR, and NOT.


                                        Operator                    Description
                                           and      Returns True if both operands are true

                                            or      Returns True if at least one operand is true
                                           not      Returns True if operand is false

                 Program 8: To demonstrate the use of logical operators

                 # Uses of Logical Operators

                 x = 10
                 y = 5
                 z = 20

                 # Logical AND: True if both conditions are True
                 logical_and_result = (x > y) and (y < z)
                 print("Logical AND Result:", logical_and_result)

                 # Logical OR: True if at least one condition is True

                 logical_or_result = (x < y) or (y < z)
                 print("Logical OR Result:", logical_or_result)

                 # Logical NOT: Inverts the result, True becomes False and False becomes True


                 58     Touchpad Artificial Intelligence - XI
   55   56   57   58   59   60   61   62   63   64   65