Page 92 - modular4.0
P. 92

Chapter Profile
                  Program 1: To perform all the arithmetic operations

                      Program1.py

                   File  Edit  Format    Run   Options   Window    Help

                   #Program to perform from arithmetic operators
                   a = 9
                   b = 4
                   add = a + b    #Addition
                   sub = a - b    #Subtraction
                   mul = a * b    #Multiplication
                   div = a / b    #Division
                   divl =a // b   #Floor Division
                   mod = a % b    #Modulus
                   power = a **b  #Power
                   print ("Sum is : ", add, " Difference is : " , sub, " Product is : "
                   ,mul, " Decimal division is : ", div, " Integer division is : " ,divl,"
                   Remainder is : ", mod, " Raised to the power is : ", power)




                  On running the above program, we get the following output:

                      Output

                   Sum is : 13  Difference is :  5  Product is :  36  Decimal division is :  2.25
                   Integer division is :  2  Remainder is :  1  Raised to the power is : 6561




                  Assignment Operators

                  The assignment operators are used to assign the value of the right expression to the left operand.
                  The assignment operators are described in the following table:


                   Operator         Name                               Description                          Example

                       =       Assignment        It assigns the value of operand on the right side to the     x = 5
                                                 left side operand.
                       +=      Addition          It adds right operand to the left operand and assigns        x += 3
                               assignment        the result to left operand. x+=3 is equivalent to x=x+3.

                       –=      Subtraction       It subtracts right operand from the left operand and         x –= 3
                               assignment        assigns the result to left operand. x–=3 is equivalent to
                                                 x=x–3.

                       *=      Multiplication    It multiplies right operand with the left operand and        x *= 3
                               assignment        assigns the result to left operand. x*=3 is equivalent to
                                                 x=x*3.

                       /=      Division          It divides left operand with the right operand and           x /= 3
                               assignment        assigns the result to left operand. x/=3 is equivalent to
                                                 x=x/3.



                90   Modular (Ver. 4.0)-VI
   87   88   89   90   91   92   93   94   95   96   97