math function in python

math function in python:




Yes , we can find a square of a number ,cube of number a factorial by direct calculations but python provides some inbuild functions to avoid a manual calculations and vast code  . But the important thing is we have to import the math function if user not  import the math function the compiler pass the error 

1.how to import math function in python ?

In python there are several modules but to use them we have to ask the compiler and syntax for it 

-Syntax:" import math "


Ones we call this module we are free to use any inbuild math function ,to use the math function we have to say math.(function name )
e.g. to find a square root of a number

import math
x=25
math.sqrt(x)
print(x)

//Output=5


we  have some more inbuild functions like 
exponential 
factorial 
sin, cos
sinh , cosh (Hyperbolic) 
log
gcd
power 
mod
radians
ceil
floor  etc
there are some constant values as well like 
e
pi
etc 

we will discuss with some of important function

1."factorial function in python math
- x=5
 import math
 math.factorial(x)
print(x)
//output 120






 when we want only integer value from a float value  we use ceil and floor functions 


2.ceil:
when we use ceil it will convert value into an integer ,it will return the celling value ,smallest integer not less than particular variable
let us assume
a=3.4
b=2.9 
import math
math.ceil(a)
math.ceil(b)

the output will be 4 and 3 

3.floor;
 floor method simply returns floor value of that particular variable
largest integer not greater than x
e.g.
a=3.4
b=2.9
import math 
math.floor(a)
math.floor(b)

//output 3,2 respectively 

4.Power function:

power function is used to find square ,cube and raised to any number value in python
its syntax is math.pow(a,b)  returns a raised to b value
e.g.
import math 
math.pow(4,3)

output // 64.0

5.Constant:

There are some constant values in float form  like "pi" and "e"
to print this values in python
import math
print(math.pi)
print(math.e)
 and it will print accurate values of pi and e





In above examples to use math functions we have to call math.(function name) every time ,to avoid this there is special syntax 
"import math as m"
then we can use math function by both syntax
e.g.
import math as m
math.sqrt(25)
//or
m.sqrt(25)

Both will return answer i.e. 5


 I hope this article on math function is helpful for u..
          



                                                                   Thank u 😊…..