8000 Create Modules.py · Gopal-py/gk-learn-python@6f54b16 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f54b16

Browse files
authored
Create Modules.py
General usage of Modules
1 parent ac3407c commit 6f54b16

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# importing built-in module math
2+
import math
3+
4+
# using square root(sqrt) function contained
5+
# in math module
6+
print(math.sqrt(25))
7+
8+
# using pi function contained in math module
9+
print(math.pi)
10+
11+
# 2 radians = 114.59 degrees
12+
print(math.degrees(2))
13+
14+
# 60 degrees = 1.04 radians
15+
print(math.radians(60))
16+
17+
# Sine of 2 radians
18+
print(math.sin(2))
19+
20+
# Cosine of 0.5 radians
21+
print(math.cos(0.5))
22+
23+
# Tangent of 0.23 radians
24+
print(math.tan(0.23))
25+
26+
# 1 * 2 * 3 * 4 = 24
27+
print(math.factorial(4))
28+
29+
# importing built in module random
30+
import random
31+
32+
# printing random integer between 0 and 5
33+
print(random.randint(0, 5))
34+
35+
# print random floating point number between 0 and 1
36+
print(random.random())
37+
38+
# random number between 0 and 100
39+
print(random.random() * 100)
40+
41+
List = [1, 4, True, 800, "python", 27, "hello"]
42+
43+
# using choice function in random module for choosing
44+
# a random element from a set such as a list
45+
print(random.choice(List))
46+
47+
48+
# importing built in module datetime
49+
import datetime
50+
from datetime import date
51+
import time
52+
53+
# Returns the number of seconds since the
54+
# Unix Epoch, January 1st 1970
55+
print(time.time())
56+
57+
# Converts a number of seconds to a date object
58+
print(date.fromtimestamp(454554))

0 commit comments

Comments
 (0)
0