forked from alecktony/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14_Python - Modules.py
77 lines (50 loc) · 1.5 KB
/
14_Python - Modules.py
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
import calc
def add(x, y):
return (x + y)
def subtract(x, y):
return (x - y)
print add(10, 2)
print subtract(2, 26)
from math import sqrt, factorial
print sqrt(6)
print factorial(5)
# importing built-in module math
import math
# using square root(sqrt) function contained
# in math module
print math.sqrt(25)
# using pi function contained in math module
print math.pi
# 2 radians = 114.59 degreees
print math.degrees(2)
# 60 degrees = 1.04 radians
print math.radians(60)
# Sine of 2 radians
print math.sin(2)
# Cosine of 0.5 radians
print math.cos(0.5)
# Tangent of 0.23 radians
print math.tan(0.23)
# 1 * 2 * 3 * 4 = 24
print math.factorial(4)
# importing built in module random
import random
# printing random integer between 0 and 5
print random.randint(0, 5)
# print random floating point number between 0 and 1
print random.random()
# random number between 0 and 100
print random.random() * 100
List = [1, 4, True, 800, "python", 27, "hello"]
# using choice function in random module for choosing
# a random element from a set such as a list
print random.choice(List)
# importing built in module datetime
import datetime
from datetime import date
import time
# Returns the number of seconds since the
# Unix Epoch, January 1st 1970
print time.time()
# Converts a number of seconds to a date object
print date.fromtimestamp(454554)