- Home
- Course Detail
regularpython@gmail.com
You are now watching:
Python Math Module / of Python Math Module
import math
# ceil(x) : Returns the smallest integer greater than or equal to x.
x = 2.9
print(f'{x} value converted into ',math.ceil(x))
x = 2.0
print(f'{x} value converted into ',math.ceil(x))
x = 2.6
print(f'{x} value converted into ',math.ceil(x))
# floor(x) : Returns the largest integer less than or equal to x
print()
print("| floor |".center(50,"*"))
x = 2.1
print(f'{x} value converted into ',math.floor(x))
x = 2.0
print(f'{x} value converted into ',math.floor(x))
x = 2.6
print(f'{x} value converted into ',math.floor(x))
# fabs(x) : Returns the absolute value of x
print()
print("| fabs |".center(50,"*"))
x = -2.6
print(f'{x} value converted into ',math.fabs(x))
x = 2
print(f'{x} value converted into ',math.fabs(x))
# factorial(x):Returns the factorial of x
print()
print("| factorial |".center(50,"*"))
x = 2 #n(n-1)
print(f'{x} value converted into ',math.factorial(x))
x = 3 #n(n-1)(n-2) = 3*2*1
print(f'{x} value converted into ',math.factorial(x))
x = 5 #n(n-1)(n-2)(n-3)(n-4) = 5*4*3*2*1 = 120
print(f'{x} value converted into ',math.factorial(x))
# fmod(x, y):Returns the remainder when x is divided by y
print()
print("| fmod |".center(50,"*"))
x, y = 4 , 2
print(f'{x} value converted into ',math.fmod(x, y))
x, y = 3 , 2
print(f'{x} value converted into ',math.fmod(x, y))
# fsum(iterable):Returns an accurate floating point sum of values in the iterable
print("| fsum |".center(50,"*"))
x = [1,2,3,4,5]
print(sum(x))
print(f'{x} value converted into ',math.fsum(x))
# isnan(x):Returns True if x is a NaN
print("| isnan |".center(50,"*"))
x = (10.0 ** 200) * (10.0 ** 200)
y = x/x
print(x)
print(y)
print(f' value converted into ',math.isnan(x))
print(f' value converted into ',math.isnan(y))
print(f' value converted into ',math.isinf(x))
# exp(x) : Returns e**x
print("| exp |".center(50,"*"))
x = 2
print(f'{x} value converted into ',math.exp(x))
# pow(x, y) : Returns x raised to the power y
print("| pow(x, y) |".center(50,"*"))
x,y = 2,4
print(f'{x},{y} value converted into ',math.pow(x,y ))
print(2**4)
# sqrt(x): Returns the square root of x
print("| sqrt(x) |".center(50,"*"))
x = 2
print(f'{x} value converted into ',math.sqrt(x))
# max(x1, x2,...)
print("| max(x1, x2,...) |".center(50,"*"))
x = [1, 3, 7, 8, 3]
print(f'{x} value converted into ',max(x))
# min(x1, x2,...)
print("| min(x1, x2,...) |".center(50,"*"))
x = [1, 3, 7, 8, 3]
print(f'{x} value converted into ',min(x))