Page 94 - PlugGPT_V2.0_C7_Flipbook
P. 94

Program 2: To perform all the assignment operators

                      Program2.py
                   File  Edit  Format   Run    Options   Window    Help


                   #example of arithmetic operators
                   a = 21
                   b = 10
                   c = 0

                   c = a + b
                   print(c)
                   c += a
                   print(c)
                   c *= a
                   print(c)
                   c /= a
                   print(c)
                   c %= a
                   print(c)
                   c **= a
                   print(c)
                   c //= a
                   print(c)




                  The output of the above program is:
                      Output

                   31
                   52
                   1092
                   52.0
                   10.0
                   1e+21
                   4.761904761904762e+19



                  Logical Operators

                  Logical operators are used to combine conditional statements as operand. They return either

                  True or False. Python supports the following logical operators:


                   Operator Name                     Description                      Example (x=2)          Output
                      and       AND  It returns true, if both operands are       (x < 5) and (x < 10)         TRUE

                                        true.

                       or        OR     It returns true, if one of the operands  (x < 5) or (x < 2)           TRUE
                                        is true.
                      not       NOT     It reverses the result, returns false, if   not [(x < 5) and (x < 10)]  FALSE
                                        the result is true or vice versa.



               92       Premium Edition-VII
   89   90   91   92   93   94   95   96   97   98   99