Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 144 - CodePilot V5.0 C6
P. 144

    Program 6 To demonstrate the use of all the assignment operators.

                           Program6.py
                        File  Edit  Format   Run   Options   Window    Help

                        # Assign values to variables
                        a = 5
                        y = 3
                        # Assignment (=)
                        x = a
                        print("Assignment: x =", x)
                        # Addition assignment (+=)
                        x += a
                        print("Addition Assignment (+=): x =", x)
                        # Subtraction assignment (-=)
                        x -= y
                        print("Subtraction Assignment (-=): x =", x)
                        # Multiplication assignment (*=)
                        x *= y
                        print("Multiplication Assignment (*=): x =", x)
                        # Division assignment (/=)
                        x /= y
                        print("Division Assignment (/=): x =", x)
                        # Modulus assignment (%=)
                        x %= y
                        print("Modulus Assignment (%=): x =", x)
                        # Floor division assignment (//=)
                        x //= y
                        print("Floor Division Assignment (//=): x =", x)
                        # Exponentiation assignment (**=)
                        x **= y
                        print("Exponentiation Assignment (**=): x =", x)

                            Output

                         Assignment: x = 5
                         Addition Assignment (+=): x = 10
                         Subtraction Assignment (-=): x = 7
                         Multiplication Assignment (*=): x = 21
                         Division Assignment (/=): x = 7.0
                         Modulus Assignment (%=): x = 1.0
                         Floor Division Assignment (//=): x = 0.0
                         Exponentiation Assignment (**=): x = 0.0

                       142
                            CodePilot (V5.0)-VI

         5

| 139 140 141 142 143 144 145 146 147 148 149 |