### Working with Numbers

In this lesson we are working with numbers and different arithmetic operations. Python support different types of arithmetic operations like,

2. Subtraction
3. Division
4. Multiplication
5. Exponentiation
6. Modulo
7. Floor Division

You can add numbers by simply mentioning two or more numbers, connected by addition operator “+”

Example :

``` 3 + 3
6
```

#### Subtraction

You can subtract one number from another number by connecting the subtraction operator “-“

Example :

``` 6 - 3
3
```

#### Multiplication

To multiply one number with another, both needs to be connected by multiplication operator “*”

Example :

``` 6 * 3
18
```

#### Division

To perform the division of two numbers, the division operator “/” can be used.

Example :

``` 6 / 3
2
```

#### Exponentiation

Exponentiation stands for the multiplying the number n number of times and exponentiation operator is represented by **

Example :

``` 6 ** 2
36
```

#### Modulo

The modulo operator is represented using the symbol “%”. The modulo operator returns the remainder of dividing the left hand operand by right hand operand.

Example :

``` 37 % 3
1
```

#### Floor Division

The floor division operator is represented using the symbol “//”. Floor division returns the quotient, answer or the result of division, in which the digits after the decimal point will be removed. But if one of the operands(dividend and divisor) is negative, then the result is floored, means rounded away from zero, which means towards the negative of infinity.

Example :

``` 37 // 3
12
```
Operator Name Symbol Sample Operation Output
Addition + 5 + 5 10
Subtraction 10 – 6 4
Multiplication * 8 * 6 48
Division / 37 / 3 12.3333
Exponentiation ** 6 ** 2 36
Modulo % 37 % 3 1
Floor Division // 37 // 3 12

In the below excercise, we performing the operations using the operators mentioned in this lesson.

``` ``` ``` #Print the sum of values 5 and 6 sum = 5 + 6 print(sum) #Subtract 4 from 10 and print the value diffr = 10 - 4 print(diffr) #Multiple 3 with 9 and print the value mult = 3 * 9 print(mult) #Divide 56 with 2 and print the value div = 56 / 2 print(div) #Combination of arithmetic operation and print the value total = 21 + 45 * 78 / 67.6 print(total) # Test the Exponentiation operator. Perform exponentiation 8 to the power of 6 exp = 8 ** 6 print(exp) # Modulo operator. Obtain the remainder of division modl = 37 % 3 print(modl) # Floor Division operator. Obtain the remainder of floor division flr = 37 // 3 print(flr) ``` ``` # Print the sum of values 5 and 6 11 # Subtract 4 from 10 and print the value 6 # Multiply 3 with 9 and print the value 27 # Divide 56 with 2 and print the value 28.0 #Combination of arithmetic operation and print the value 72.92307692307693 # Test the Exponentiation operator. Perform exponentiation 8 to the power of 6 262144 # Modulo operator. Obtain the remainder of division 1 # Floor division operator. Obtain the remainder of floor division 12 ``` ``` msg = "Do not remove the other arithmetic examples!" ```

This site uses Akismet to reduce spam. Learn how your comment data is processed.