import threading
import time
class Car(threading.Thread):
def init(self):
self.i=0
def run(self):
i=1
while(i<=10):
if(self.getName()=="Ciaz"):
time.sleep(1)
if (self.getName() == "Swift" and self.i >= 3):
break
print(self.getName(),"Car Is Running....")
i+=1
self.i+=1
swift=Car()
swift.init()
swift.setName("Swift")
swift.start()
ciaz=Car()
ciaz.init()
ciaz.setName("Ciaz")
ciaz.start()
Output:
Swift Car Is Running....
Swift Car Is Running....
Swift Car Is Running....
Ciaz Car Is Running....
Ciaz Car Is Running....
Ciaz Car Is Running....
Ciaz Car Is Running....
Ciaz Car Is Running....
Ciaz Car Is Running....
Ciaz Car Is Running....
Ciaz Car Is Running....
Ciaz Car Is Running....
Ciaz Car Is Running....
Python program for multithreaded with class
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer