-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreading.py
More file actions
22 lines (17 loc) · 823 Bytes
/
threading.py
File metadata and controls
22 lines (17 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import threading # import the thread module
import time # import time module
def cal_sqre(num): # define the cal_sqre function
print(" Calculate the square root of the given number")
for n in num:
time.sleep(0.3) # at each iteration it waits for 0.3 time
print(' Square is : ', n * n)
def cal_cube(num): # define the cal_cube() function
print(" Calculate the cube of the given number")
for n in num:
time.sleep(0.3) # at each iteration it waits for 0.3 time
print(" Cube is : ", n * n *n)
arr = [4, 5, 6, 7, 2] # given array
t1 = time.time() # get total time to execute the functions
cal_sqre(arr) # call cal_sqre() function
cal_cube(arr) # call cal_cube() function
print(" Total time taken by threads is :", time.time() - t1) # print the total time