th

 avatar
user_7840863
plain_text
2 months ago
2.4 kB
1
Indexable
Never
import threading

class f(threading.Thread):
    def __init__(self,n):
        super().__init__()
        self.__n=n
       
    def run(self):
        if self.__n%2==0:
            print(self.__n," is even")
        else:      
            print(self.__n," is odd")
              

def main():
    x=int(input("Enter the num1:"))
    y=int(input("Enter the num2:"))
    for i in range(x,y+1):
        x=f(i)
        x.start()
        
main()        

**************************************************
#Q1
import threading

class Draw(threading.Thread):
    def __init__(self,i):
        threading.Thread.__init__(self)
        self.__i=i
        
    def run(self):
        for x in range (10):
                 
            print(self.__i)
        
def main():
    D1= Draw('*')
    D1.start()

    D2= Draw('#')
    D2.start()
       
    
    
    
main()




***********************************************************************

#Q2
import threading

class fact(threading.Thread):
    def __init__(self,num):
        threading.Thread.__init__(self)
        self.__num=num
        
    def run(self):
        if self.__num>= 0:
            if self.__num==0 or self.__num==1:
                print("The factorial of",num,"is:1")
            else:
                fact=1
                for i in range(1,self.__num+1):
                    fact*=i
                print("The factorial of",self.__num,"is: ",fact) 
def main():
    x=int(input("please enter the first number"))
    y=int(input("please enter the second number"))
    
    for i in range(x,(y+1)):
        f=fact(i)
        f.start()
       

    
main()
*******************************************************************


            

import threading 

class th(threading.Thread):
    def __init__(self,n):
        threading.Thread.__init__(self)
        self.__n=n
        
    def run(self):
        if(self.__n%2==0):
            print(self.__n," is even number")
        else:
            print(self.__n," is odd number")    

def main():
    n1=int(input("please enter the first number "))
    n2=int(input("please enter the second number "))
    List=[]
    for i in range(n1,n2+1):
        obj=th(i)
        List.append(obj)
        
    for j in List:
        j.start()
        
main()
        
Leave a Comment