IT Math Functions
IT Math Functions
Functions):
In python a number of mathematical operations can be performed with ease by importing a
module named “math” which defines various functions which makes our tasks easier.
1. ceil() :- This function returns the smallest integral value greater than the number. If
number is already integer, same number is returned.
a = 2.3
Output:
2. floor() :- This function returns the greatest integral value smaller than the number. If number is
already integer, same number is returned.
a = 2.3
Output:
a = -10
b= 5
Output:
a = -10
b = 5.5
Output:
Output:
Output:
3. log2(a) :- This function computes value of log a with base 2. This value
is more accurate than the value of the function discussed above.
Output:
Output:
Output:
Output:
a = math.pi/6
Output:
2. cos() :- This function returns the cosine of value passed as argument. The value passed in
this function should be in radians.
a = math.pi/6
Output:
import math
a = math.pi/6
Output:
The value of tangent of pi/6 is : 0.5773502691896257
4. hypot(a, b) :- This returns the hypotenuse of the values passed in
arguments. Numerically, it returns the value of sqrt(a*a + b*b).
b =3
c =4
Output:
a = math.pi/6
Output:
b = 30
# returning the converted value from degrees to radians
print ("The converted value from degrees to radians is : ", end="")
print (math.radians(b))
Output:
a =4
Output:
Output:
Output:
Output:
2. randrange(beg, end, step) :- This function is also used to generate random number but
within a range specified in its arguments. This function takes 3 arguments, beginning
number (included in generation), last number (excluded in generation) and step ( to skip
numbers in range while selecting).
Output:
3. random() :- This number is used to generate a float random number less than 1 and greater
or equal to 0.
4. seed() :- This function maps a particular random number with the seed
argument mentioned. All random numbers called after the seeded value returns
the mapped number.
import random
# using seed() to seed a random number
random.seed(5)
Output:
# Initializing list
li = [1, 4, 5, 10, 2]
Output:
6. uniform(a, b) :- This function is used to generate a floating point random number between
the numbers mentioned in its arguments. It takes two arguments, lower limit(included in
generation) and upper limit(not included in generation).