-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmathT.py
More file actions
91 lines (53 loc) · 3.98 KB
/
Copy pathmathT.py
File metadata and controls
91 lines (53 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# ===================== SUMMARY OF math MODULE =====================
# math module is used for mathematical operations in Python.
# It provides functions for square root, power, factorial, gcd, ceil, floor, etc.
# It also provides constants like math.pi and math.e.
# math.sqrt() gives square root of a number.
# math.pow() gives power but returns answer in float.
# math.floor() gives lower integer value.
# math.ceil() gives upper integer value.
# math.trunc() removes decimal part only.
# math.factorial() gives factorial of a number.
# math.gcd() gives greatest common divisor.
# math.sin(), math.cos(), math.tan() work with angles in radians.
# math.radians() converts degree into radians.
# math.degrees() converts radians into degree.
# ================================================================
import math # importing the math module
print(math.pi) # printing value of pi
print(math.e) # printing value of Euler's number e
print(math.sqrt(25)) # finding square root of 25
print(math.pow(2, 3)) # finding 2 raised to power 3, returns float
print(2 ** 3) # finding 2 raised to power 3 using normal power operator
print(math.factorial(5)) # finding factorial of 5, means 5*4*3*2*1
print(math.gcd(12, 18)) # finding greatest common divisor of 12 and 18
print(math.lcm(12, 18)) # finding least common multiple of 12 and 18
print(math.floor(4.9)) # gives lower integer value, answer is 4
print(math.ceil(4.1)) # gives upper integer value, answer is 5
print(math.trunc(4.9)) # removes decimal part, answer is 4
print(math.trunc(-4.9)) # removes decimal part, answer is -4
print(math.fabs(-10)) # gives absolute value as float
print(abs(-10)) # gives absolute value using built-in function
print(math.isqrt(26)) # gives integer square root, decimal part removed
print(math.prod([2, 3, 4])) # multiplies all values of list, answer is 24
print(math.fsum([0.1, 0.2, 0.3])) # gives accurate floating point sum
print(sum([0.1, 0.2, 0.3])) # normal sum may give small floating point error
print(math.remainder(10, 3)) # gives IEEE-style remainder
print(10 % 3) # gives normal modulus remainder
print(math.log(10)) # gives natural log of 10, base e
print(math.log10(100)) # gives log of 100 with base 10
print(math.log2(8)) # gives log of 8 with base 2
print(math.exp(2)) # gives e raised to power 2
degree = 90 # storing angle in degree
radian = math.radians(degree) # converting degree into radians
print(radian) # printing radian value
print(math.sin(radian)) # finding sin of 90 degree
print(math.cos(radian)) # finding cos of 90 degree
print(math.tan(radian)) # finding tan of 90 degree
print(math.degrees(radian)) # converting radians back into degrees
print(math.isfinite(100)) # checks whether number is finite
print(math.isinf(math.inf)) # checks whether number is infinity
print(math.isnan(math.nan)) # checks whether value is NaN, means Not a Number
radius = 7 # storing radius of circle
area = math.pi * radius * radius # calculating area of circle using pi*r*r
print("Area of circle:", area) # printing area of circle