Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Guessuing_Game/Q1_TS.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
32 lines (25 sloc)
918 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math #importing library for the code | |
from time import time | |
import threading | |
from time import time,sleep | |
from threading import Lock | |
t0 = time() #stating time | |
values= [12,20,4,100,64,77,200,9,10] # array to be calulated | |
def mycosine(n): #funtion for calculating cosie | |
return math.cos(n) | |
def concurrent_cosines(): #functionn for printing cosine functions | |
sleep(1) | |
for val in values: | |
res = mycosine(val) | |
print('Cosine of %s is %s' % (val,res), '\n') | |
sleep(1) | |
t = threading.Thread(target=concurrent_cosines) | |
t2 = threading.Thread(target=concurrent_cosines) | |
t3= threading.Thread(target=concurrent_cosines) | |
t.start() | |
t2.start() | |
t3.start() | |
t.join() | |
t2.join() | |
t3.join() | |
print("total time taken:"+str(time()-t0)) |