Skip to main content

Math Functions

Enter your email address:

मैल पर फीड बर्नर से प्राप्त लिंक Verify करे


Math Functions

Math module is standard module already available in python. We have to import math module to use their functions. 

sqrt():
Return square root of given number

import math
print(math.sqrt(25)) #5
print(math.sqrt(49)) #7


factorial(x) 
Return the factorial of given Number.
print(math.factorial(5))  #120

pow(x, y)
Returns x raised to the power y
import math
print(math.pow(3,3)) #27

ceil()
Round a number upward to its nearest integer:
import math
print(math.ceil(4.3))  # 5
print(math.ceil(5.6)) # 6
print(math.ceil(-5.6)) # -5

floor()

Round a number downward to its nearest integer

import math
print(math.floor(4.3))  # 4
print(math.floor(5.6)) # 5
print(math,floor(-5.6)) # -6

fmod(x, y)
Find remainder after dividing x by y.
print(math.reminder(10,4))  #2
print (math.fmod(67, 7))  # 4

fabs() 
Return absolute value( remove the sign of given number
print(math.fabs(-35))  # 35


fsum(iterable)
Return sum of the elements in an iterable object

list=[1,2,3,5]
print(fsum(list)) #11

gcd(x, y)
Returns the highest value that can divide two integers
print(math.gcd(4,6))  #2

log10( ) 
return the base-10 logarithm of  given number
print(math.log10(2)) #0.3010299956639812
print(math.log10(1)) #0.0

log2( ) 
return the base-2 logarithm of  given number
print(math.log2(2)) #1.0
print(math.log2(1)) #0.0



cos()
Return the cosine value of given number
print (math.cos(0))  # 1.0

sin()
Return the sine value of given number
print (math.sin(0))  # 0.0

tan()
Return the tangent value of given number
print (math.tan(0))  # 0.0

acos()
Return the arc cosine value of  given number
The parameter passed in acos() must lie between -1 to 1.
-1 will return the value of PI.
print (math.acos(1))  # 0.0

asin()
Return the arc sine value of numbers
The parameter passed in asin() must lie between -1 to 1.
1 will return the value of PI/2, and -1 will return the value of -PI/2.
print (math.asin(0))  # 0.0

atan()
Return the arc tangent value of numbers
print (math.atan(0))  # 0.0

degrees()
Convert angles from radians to degrees.
PI (3.14..) radians are equal to 180 degrees, which means that 1 radian is equal to 57.2957795 degrees.

print (math.degrees(1))  #57.29577951308232
print (math.degrees(3.14))  #179.9087476710785

radians()
Converts angles from degrees to radians
print(math.radians(180))   #3.141592653589793

exp(x):
Find the exponential value of a given x number
Returns e**x
where E is Euler's number (approximately 2.718281...)

print(math.exp(65))  #  1.6948892444103338e+28

infinite() :
Check whether given value is finite or not
print (math.isfinite (56)) # true
print (math.isfinite (-45.34)) #true
print (math.isfinite (+45.34)) #true
print (math.isfinite (math.inf)) #false
print (math.isfinite (float("nan"))) #false



Constants in Math Module

pi :        Return the value of pi: 3.141592
e:         Return the value of  Euler's number (natural base)  e is                  0.718282
non:    floating-point NaN (Not a Number) value
inf :    Print the positive and negative infinity:





Comments

Popular posts from this blog

Revision basics of Python covered in Class XI

Python Function Basics