Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 124 - 2612_Digimind
P. 124

    To demonstrate the use of all the arithmetic operations.

                          Program3.py

                       File  Edit  Format   Run    Options   Window    Help

                       x = 5
                       y = 3

                       result_add = x + y # Addition
                       print("Addition:", result_add)

                       result_sub = x - y # Subtraction

                       print("Subtraction:", result_sub)

                       result_mul = x * y # Multiplication
                       print("Multiplication:", result_mul)

                       result_div = x / y # Division
                       print("Division:", result_div)

                       result_mod = x % y # Modulus

                       print("Modulus:", result_mod)

                       result_exp = x ** y # Exponentiation
                       print("Exponentiation:", result_exp)

                       result_floor = x // y # Floor Division
                       print("Floor Division:", result_floor)

                          Output

                       Addition: 8
                       Subtraction: 2
                       Multiplication: 15
                       Division: 1.6666666666666667
                       Modulus: 2
                       Exponentiation: 125
                       Floor Division: 1

                      RELATIONAL OPERATORS

                      Relational operators compare values on both sides and return True or False. The following table
                      describes the relational operators:

                      122   Premium Edition-VII

| 119 120 121 122 123 124 125 126 127 128 129 |