Posts

ProcessPoolExecutor vs ThreadPoolExecutor

Image
  from concurrent.futures import ProcessPoolExecutor, as_completed import  time def prime_number1 (num_list): final_pr_list =[] for num in range ( 2 , num_list+ 1 ): pr_list = [] for i in range ( 2 ,num+ 1 ): if num%i == 0 : pr_list.append(num) if len (pr_list)== 1 : final_pr_list.append(num) else : pass return final_pr_list def prime_number2 (num_list): final_pr_list =[] for num in range ( 2 , num_list+ 1 ): pr_list = [] for i in range ( 2 ,num+ 1 ): if num%i == 0 : pr_list.append(num) if len (pr_list)== 1 : final_pr_list.append(num) else : pass return final_pr_list def fibonacci_series1 (num): fibo_list =[] a,b = 0 , 1 for i in range (num+ 1 ): c = a+b a = b b = c fibo_list.append(c) return fibo_list def fibonacci_series2 (num): fibo...

Multithreading in python

 import threading import time def print_numbers():     for i in range(11115):         time.sleep(1)         print(f"Thread 1: {i}") def print_letters():     for letter in 'ABCDE':         time.sleep(1)         print(f"Thread 2: {letter}") # Create two threads thread1 = threading.Thread(target=print_numbers) thread2 = threading.Thread(target=print_letters) # Start the threads thread1.start() thread2.start() # Wait for both threads to finish thread1.join() thread2.join() print("Both threads have finished.")

Client socket programm

  import socket s = socket.socket() try :     s.connect(( "localhost" , 1234 ))     print( "Client is ready and connected to server" ) except :     print( "Failed to connect with server" ) conn_status = True while conn_status:     incoming_message = s.recv( 1024 )     incoming_message = incoming_message.decode()     print( "Server: >>" , incoming_message)     message = input( "Client1: >> " )     message = message.encode()     s.send(message)

Server Socket programm

  import socket s = socket.socket() try:     s.bind(("localhost", 1234))     print("Server is ready") except:     print("Server is not ready") s.listen() conn, add = s.accept() print(add, "has connected") conn_status = True while conn_status:     message = input("Server: >> ")     message = message.encode()     conn.send(message)     incoming_msg = conn.recv(1024)     incoming_msg = incoming_msg.decode()     print("Client: >> ", incoming_msg)

Star pattern in Java

  public class pattern_practice {     public static void main ( String [] args ) {         // for(int i=0;i<5;i++){         //     for(int j=0;j<=i;j++){         //       System.out.print("*");         //     }         //     System.out.print("\n");         // }         //////////////////////////////         // int m = 0;         // for(int i=0;i<5;i++){         //     for(int j=1;j<=i;j++){         //       System.out.print(m);         //       m=m+1;         //     }         //     System.out.print("\n");         // }           ...

Gues random number

  import random i = 0 randon_range = int ( input ( "Enter range=" )) while True :     n = int ( input ( "Your Gues the number =" ))     x = random . randint ( 0 , randon_range )     print ( "Computer gues=" , x )       if x == n :         print ( "****You won****" )         i = i + 1         break     else :         i = i + 1         print ( "!!!!!!You loos!!!!!!!" )     print ( "Number of gues=" , i )

convert string>>dictionary >>list >> string

  input_new = list ( string2 ) sort_list = input_new . sort () d = { x : input_new . count ( x ) for x in input_new } l = [] for key , value in d . items ():       l . append ( key )       l . append ( str ( value )) print ( '' . join ( l ))

star pattern

  k = 3 for i in range ( 1 , 9 ):     if i % 2 != 0 :         print ( " " * k + "*" * i )         k = k - 1 k = 6 m = 1 for i in range ( 1 , 5 ):     for j in range ( 1 ,k - i):         print (m, end = " " )         m = m + 1     print ( " \n " )    

Prime Number

####### Prime Number####### n = int ( input ( "Enter any number:" )) flag = 0 i = 2 while ( i < n ):     if n % i == 0 :         flag = 1         break     i = i + 1 if flag == 1 :     print ( "Not a prime number" ) elif n == 1 :     print ( "Not a prime number" ) else :         print ( "It is prime number" )   or  for i in range ( 1 , 101 ):     k = []     for j in range ( 1 , i + 1 ):         if i % j == 0 :             k . append ( j )     if len ( k ) == 2 :         print ( i )

Lalita_YouTube_Downloader v1.1

  from tkinter import * from tkinter . ttk import Progressbar from tkinter import ttk import pytube from tkinter import messagebox root = Tk () root . title ( "Lalita Youtube Downloader" ) root . geometry ( "600x400" ) def retrieve_input ():     try :         link = textBox . get ( "1.0" , "end-1c" )         print ( link )         ytube = pytube . YouTube ( link )         choice = v . get ()         if choice == 0 :             res = "360p"             ytube . streams . get_by_resolution ( res ). download ()         if choice == 1 :             res = "480p"             ytube . streams . get_by_resolution ( res ). download ()         if choice == 2 :             res ...

Lalita_YouTube_Downloader v1.0

  import pytube print ( "******** Welcome to e-lalita Youtube Downloader ********" ) def youtube_downloder ():         link = input ( "Enter any youtube link : " )         res = input ( "Choose any one resolution from 144p, 360p, 720p & 1080p: " )         ytube = pytube . YouTube ( link )         print ( "Title:" , ytube . title )         print ( "Author:" , ytube . author )         print ( "Published date:" , ytube . publish_date . strftime ( "%Y-%m- %d " ))         print ( "Number of views:" , ytube . views )         print ( "Length of video:" , ytube . length , "seconds" )         ytube . streams . get_by_resolution ( res ). download ()         print ( " \n Video successfullly downloaded from" , link ) while True :     try :         youtube_dow...

elalita NewsApp

import io import webbrowser import requests from tkinter import * from urllib.request import urlopen from PIL import ImageTk,Image class NewsApp:     def init(self):         # fetch data         self.data = requests.get('https://newsapi.org/v2/top-headlines?country=in&apiKey=07ce6431517e45c5b04b589c36e5bed6').json()         # initial GUI load         self.load_gui()         # load the 1st news item         self.load_news_item(0)     def load_gui(self):         self.root = Tk()         self.root.geometry('350x600')         self.root.resizable(0,0)         self.root.title('e-lalita News App')         self.root.configure(background='black')     def clear(self):         for i in self.root.pack_slaves():     ...

search any element in Dictionary

      j = int ( input ( "Any element to find in dictionary " ))       d ={ 1 : 2 , 3 : 4 , 5 :{ 11 : 12 }, 7 : 8 } l = list ( d . values ()) k =[] for i in l :         if isinstance ( i , int ):                 k . append ( i )         if isinstance ( i , dict ):                 l = k . append ( list ( i . values ())[ 0 ])     if j in k :         print ( "It is present" )   else :         print ( "It is not present" )                

Identify the numbers within the string input

  ######print only number from given any string################ def extract_store_sort ( string ):     k =[]     for a in string :         if a .isalpha()== True :             k . append ( " " )         if a .isnumeric() == True or a == "." :             k . append ( a )             s = "" . join ( k )     k1 = s . split ()     lst = list ( map ( eval , k1 ))     print ( sorted ( lst )) string = "AC*wv12n/:#e123we2.45oin  (fwoi6n#a98nfwb+owi" extract_store_sort ( string )    
def check_prime ( x ):     lst =[]     for i in range ( 1 , x + 1 ):         if x % i == 0 :             lst . append ( i )     if len ( lst )== 2 :         print ( p , "is a prime number" )     else :         print ( p , "is not prime number" ) p = int ( input ( "Enter any number to check whether it is prime or not  = " ))     check_prime ( p )            

Take Input from user in Java

 import java.io.*; // first line step 1 public class DemoInput2 { public void abc(String name,int age) { System.out.println("name "+name+" age "+age); } public void calc() throws IOException , NumberFormatException { BufferedReader brr = new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter no1"); //String n = br.readLine();  // input 1 //String na= n.trim(); //int nn = Integer.parseInt(na); // short way int nn = Integer.parseInt(brr.readLine().trim()); System.out.println("enter no2"); //String n1 = br.readLine(); // input 2 //int nn1 = Integer.parseInt(n1); int nn1 = Integer.parseInt(brr.readLine().trim()); int sum = nn+nn1; System.out.println(sum); } public static void main(String[] args) throws IOException  // step 2 { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println(...

DemoException java

  public class DemoException { public void calculate(int i,int j) // throws Exception { System.out.println(i+j); try { System.out.println(i/j);  // expect error can come } catch(Exception e) { // e.printStackTrace();  // system print error //System.err.println("my error message");  // user error    // alternate System.out.println("alternate code "+i/1); } finally { System.out.println(i-j);   // always execute  System.out.println(i*j); } } public static void main(String[] args) throws Exception { // TODO Auto-generated method stub DemoException d = new DemoException(); d.calculate(12, 2); } }

ArrayPyramid

  public class ArrayPyramid { public static void main(String[] args) { // TODO Auto-generated method stub String palindrome = "Devendra";         int len = palindrome.length();           System.out.println("length :"+len);         char tempCharArray[]  = new char[len];   // single dimention                  // put original string in an          // array of chars         for (int i = 0; i < len; i++) {     // add values in single dimention..             tempCharArray[i] =                  palindrome.charAt(i);         }          char c[][]=new char[len][len];    // two dimention         for (int row = 0; row < len; row++) {       ...

Array In java

  public class ArrayArrange { public static void main(String[] args) { int number[]={55,40,8,65,41}; //declare         for(int i=0;i<number.length;i++)             {                   System.out.println("outer for"+i);          for(int j=i+1;j<number.length;j++)              {                     System.out.println("inner for "+j);      System.out.println(  "if("+number[i]+" > "+number[j]+")");              if(number[i] > number[j])               { System.out.println(" int temp="+number[i]);          int temp=number[i];           System.out.println("temp :"+temp);    System.out.print...

Core java Selenium Software Testing

import java.io.*; public class Assign1  { public void calc() throws IOException { BufferedReader brr=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter operator"); String o=brr.readLine().trim(); System.out.println("Enter value of a"); // String a=brr.readLine(); int a1=Integer.parseInt(brr.readLine().trim()); System.out.println("Enter value of b"); // String b=brr.readLine(); int b1=Integer.parseInt(brr.readLine().trim()); int res = 0; if(o.equals("+")) { res = a1+b1; } else if(o.equals("-")) { res = a1-b1; } System.out.println(res); } public static void main(String[] args) throws IOException { Assign1 add=new Assign1(); add.calc(); } }