Page 40 - Code & Click - 7
P. 40

Experiential Learning
              Lab Activity 3
             Program  to  accept  two  numbers  from  the  user  and  display  the  result  of  various  arithmetic
             operations on them.
             1. Type the code as shown in the image in the Python Editor.
















             2. Press the F5 key to execute the code. Sample output of the program is given.


            Assignment Operator
            The Assignment operator is used to assign a value to a variable.

             Operator         Name                                       Description

                 =         Assignment       Assigns the value on right side to the variable on the left side.
                             Addition       Adds the value on the right side to the value on the left side and
                +=
                           Assignment       assigns it to the variable on the left side. X += 2 is same as X = X + 2.

                                            Subtracts  the  value  on  the  right  side  from  the  value  on  the  left
                           Subtraction
                –=                          side and assigns it to the variable on the left side. X –= 3 is same as
                           Assignment
                                            X = X – 3.

                          Multiplication  Multiplies the value on the right side to the value on the left side and
                *=
                           Assignment       assigns it to the variable on the left side. X *= 5 is same as X = X * 5.
                             Division       Divides the value on the right side by the value on the left side and
                 /=
                           Assignment       assigns it to the variable on the left side. X /= 4 is same as X = X / 4.

                                                                                                 Experiential Learning
              Lab Activity 4
             Program to illustrate the use of Assignment operators.
             1. Type the code as shown in the image in the Python Editor.














             2. Press the F5 key to execute the code. Sample output of the program is given.



            38
   35   36   37   38   39   40   41   42   43   44   45