Skip to content

Commit 23a3eac

Browse files
committed
added example of python module math and random
1 parent e125ef4 commit 23a3eac

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

Diff for: module_math_and_random/Python_math_module_example.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#Python | math() function
2+
3+
import math
4+
5+
# Python code to demonstrate the working of
6+
7+
#demonstrate of math module to pi value
8+
print ("The pi value is : ", end="")
9+
print (math.pi)
10+
11+
#demonstrate of math module to math e value
12+
print ("The math e value is : ", end="")
13+
print (math.e)
14+
15+
#demonstrate of math module sin formula
16+
print ("The sin(10) value is : ", end="")
17+
print (math.sin(10))
18+
19+
#demonstrate of math module cos formula
20+
print ("The cos(10) value is : ", end="")
21+
print (math.cos(10))
22+
23+
#demonstrate of math module log10 formula
24+
print ("The log10(10) value is : ", end="")
25+
print (math.log10(10))
26+
27+
#demonstrate of math module for factorial function
28+
print ("The factorial value of 5 is : ", end="")
29+
print (math.factorial(5))
30+
31+
#demonstrate of math module for square root function
32+
print ("The square root value of 9 is : ", end="")
33+
print (math.sqrt(9))
34+
35+
# Python code to demonstrate the working of
36+
# ceil() and floor()
37+
38+
a = 2.3
39+
40+
# returning the ceil of 2.3
41+
print ("The ceil of 2.3 is : ", end="")
42+
print (math.ceil(a))
43+
44+
# returning the floor of 2.3
45+
print ("The floor of 2.3 is : ", end="")
46+
print (math.floor(a))
47+
48+
49+
# Python code to demonstrate the working of
50+
# fabs() and factorial()
51+
52+
a = -10
53+
b= 5
54+
55+
# returning the absolute value.
56+
print ("The absolute value of -10 is : ", end="")
57+
print (math.fabs(a))
58+
59+
# returning the factorial of 5
60+
print ("The factorial of 5 is : ", end="")
61+
print (math.factorial(b))
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#Python | random.sample() function
2+
3+
import random
4+
5+
print ("The random value from random.seed(10) is : ", end="")
6+
print (random.seed(10))
7+
#If we wanted a random integer, we can use the randint function
8+
#Randint accepts two parameters: a lowest and a highest number.
9+
#Generate integers between 1,5. The first value should be less than the second.
10+
print ("The random integer value from 10 to 100 is : ", end="")
11+
print (random.randint(10,100))
12+
13+
#If you want a larger number, you can multiply it.
14+
#For example, a random number between 0 and 100:
15+
print ("The random value of random function is : ", end="")
16+
print (random.random()*20)
17+
18+
# Python code to demonstrate the working of
19+
# randrange()
20+
print ("The random range of 1000 is : ", end="")
21+
print (random.randrange(1000))
22+
23+
print ("The random range of 10 to 100 by skipping 2 is : ", end="")
24+
print (random.randrange(10,100,2))
25+
26+
a=[1,2,9,'c','e',1.1]
27+
print ("list a value is ",a)
28+
print ("The list a value after random.shuffle function is : ", end="")
29+
random.shuffle(a)
30+
print (a)

0 commit comments

Comments
 (0)