Arithmetic operations in python- part 2

Integers and Floating-point numbers are the basic datatypes in python. Here, integers are whole numbers. It can be in both signs(positive(+),negative(-)).

Next, floating point numbers are real numbers. It can be formed by fractions.

For example,

Integers: 12,23,45,…..

Floating point numbers: 1.14, 27.89,….

A sample code for creating a integer and  float variables are given below….

f =1.14

i = 5

print(type(f))

print(type(i)

The output is shown…


Basic arithmetic operations in python  program link is given below…

https://rajeeva84.blogspot.com/2021/12/how-to-write-python-programs-for.html

Additional arithmetic operators used on numbers are

->modulus (%) operator

-> floor division(//) operator

->Exponentiation (**) operator

The sample codes are given below..

 

->modulus (%) operator

      This operator deals with the division. It gives you the reminder of the division.

For eg:

7 % 2

It gives the output as 1.

The code is

a = 7 % 2

b = 3.5 % 2

print(“The reminder of integer variable is”,a)

print(“The reminder of float variable is”,b)

Here is the output.

-> floor division(//) operator

              It is the operator used in division. It rounds of the result to the nearest number. Generally. it gives you the integer values. If you are using float numbers,it also gives the float value.

Eg:

c = 8 // 3

d = 6.5 // 3

print(“The output of the integer variable is”,c)

print(“The output of the float variable is”,d)


->Exponentiation (**) operator

 This operator is used to find the exponentiation of a given number. it is suitable for both integer and float numbers.

Eg:

e = 3

f = 2

print(“The exponentiation value of the given number is”, (e**f))

Using the same operator, we can find square root of a variable….

Eg:

g = 16

print (“The square root of a variable  is”,(g**(1/4)))

Output:


These are some operators used in mathematical operations in python variables.

No comments:

Post a Comment