You are on page 1of 5

PYTHON CLASS 18 - NUMBERS

===============================

--> All Numerical Data types are Immutable Objects

--> There are different types numerical functions such as follows:

1. Mathematical Functions
2. Random Functions
3. Trignometric Functions

eg:

>>>
>>> print(abs(100-200))
100
>>> print(abs(12343-2393435))
2381092
>>>

eg:

>>> import math


>>> print(math.ceil(101.5))
102
>>>
>>>
>>> import math
>>> print(math.ceil(107.1))
108
>>>
>>>
>>> import math
>>> print(math.ceil(-51.55))
-51
>>>
>>>
>>> import math
>>> print(math.ceil(math.pi))
4
>>>

eg:

>>> import math


>>> print(math.exp(-45.17))
2.4150062132629406e-20
>>>
>>>
>>> import math
>>> print(math.exp(math.pi))
23.140692632779267
>>>
>>>

eg:

>>> import math


>>> print(math.fabs(100-200))
100.0
>>>
>>>
>>> print(math.fabs(100.3-214.5))
114.2
>>>
>>> print(math.fabs(10+5j-20+3j))
Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
print(math.fabs(10+5j-20+3j))
TypeError: can't convert complex to float
>>>
>>>
>>>
>>> print(abs(10+5j-20+3j))
12.806248474865697
>>>

eg:

>>>
>>> import math
>>> print(math.floor(10.5))
10
>>>
>>>
>>> import math
>>> print(math.floor(-100.15))
-101
>>>
>>> import math
>>> print(math.floor(math.pi))
3
>>>
>>>
>>>
>>>

eg:

>>> import math


>>> print(math.log(5))
1.6094379124341003
>>>
>>>
>>> import math
>>> print(math.log(45))
3.8066624897703196
>>>
>>>
>>>
>>> import math
>>> print(math.log(math.pi))
1.1447298858494002
>>>
>>>
>>> import math
>>> print(math.log10(5))
0.6989700043360189
>>>
>>>
>>> import math
>>> print(math.log10(45))
1.6532125137753437
>>>
>>>
>>>
>>> import math
>>> print(math.log10(math.pi))
0.49714987269413385
>>>
>>>
>>> math.pi
3.141592653589793
>>>
>>>
>>>
>>> print(max(10,20,30,40,50))
50
>>>
>>>
>>> print(max(-10,-20,-30,-40,-50))
-10
>>>
>>>
>>>
>>>
>>> print(min(10,20,30,40,50))
10
>>> print(min(-10,-20,-30,-40,-50))
-50
>>>
>>>
>>>

eg:

>>> import math


>>> print(math.modf(100.12))
(0.12000000000000455, 100.0)
>>>
>>>
>>>
>>> import math
>>> print(math.modf(math.pi))
(0.14159265358979312, 3.0)
>>>
>>>
>>> import math
>>> print(math.modf(119))
(0.0, 119.0)
>>>

eg:

>>> import math


>>> print(math.pow(2,3))
8.0
>>>
>>>
>>>
>>> import math
>>> print(math.pow(100,2))
10000.0
>>>
>>>
>>> print(math.pow(100,-2))
0.0001
>>>
>>>
>>> print(math.pow(3,3))
27.0
>>>
>>>

eg:

>>> print(round(56.659,1))
56.7
>>>
>>>
>>>
>>> print(round(58.453454,3))
58.453
>>>
>>>
>>>
>>> print(round(345.46234,2))
345.46
>>>
>>>
>>> print(round(43.4523))
43
>>>
>>> print(round(43.5523))
44
>>>

eg:

>>> import math


>>> print(math.sqrt(25))
5.0
>>>
>>>
>>> import math
>>> print(math.sqrt(16))
4.0
>>>
>>>
>>> import math
>>> print(math.sqrt(2))
1.4142135623730951
>>>
>>>
>>> from math import sqrt
>>> print(sqrt(2))
1.4142135623730951
>>>
>>>

You might also like