Nov-17-2017, 09:43 AM
(This post was last modified: Nov-17-2017, 09:54 AM by ratanbhushan.)
Hi Team
I have a simple code in python which is below:
import threading
from random import *
class cal():
def __init__(self,a,b):
self.a=a
self.b=b
def add(self):
return self.a+self.b
for i in range(10000):
a = randint(1,10)
b = randint(1,10)
obj = cal(a,b)
print(a,'+',b,'=',obj.add())
Please advise how to achieve above using multi threading as if we run the above program in at least 10 parallel program, how to do that?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import threading from random import * class cal(): def __init__( self ,a,b): self .a = a self .b = b def add( self ): return self .a + self .b for i in range ( 10 ): a = randint( 1 , 10 ) b = randint( 1 , 10 ) obj = cal(a,b) print (a, '+' ,b, '=' ,obj.add()) |