Introduction to Python

Introduction to Python



  • Python is a High Level Programming Language.
  • Python is Interpreted,Interactive and object oriented scripting Language.
  • Python is highly readable (i.e.)Easy to understand the Code.
  • Python has fewer Syntactical constraints than other languages such as C , Java etc..


Developed By:



  • Python was developed by Dutch Programmer named Guido Van Rossum .
  • Python’s First release was in 1991.


Developed At:

  • Python was Developed at National Research Institute for Mathematics and Computer Science in Netherland.


Applications:

·        Web Programming
·        Software Applications
·        Scripting
·        Gaming and 3D Applications
·        Scientific Computing
·        Artificial Intellegence (Machine Learning, Natural Language Processing , Deep Learning  etc..)


Python is Processed at run time by the interpreter. No need to compile the program before executing it.


Versions of Python:

  • There are three Versions.
  • They are 1.x , 2.x and 3.x
  • Versions 2 and 3 are currently used.
  • Stable Release of Python 2 is Python 2.7.16 which is released on March 2019.
  • Stable Release of Python 3 is Python 3.7.4 which is released on September 2019.


Organisations that Uses Python:

·        Google
·        Facebook
·        NASA
·        IBM   etc…



Thank You ....  

C Code 34 _ To Find the sum of the elements of the array whose sum of digit is same as of the given number. [InfoGain Coding Round Question]

C Code 34 _ To Find the sum of the elements of the array whose sum of digit is same as of the given number. [InfoGain Coding Round Question]


Sample Input:

5                                 //number of elements
123  321  46  33  8     //array elements
6                                 //comparing number

Sample Output:

477                          // 123 + 321 + 33

Explanation:

The elements 123 , 321 and 33 has the sum of digit equal to as the given comparing number.
So add these elements only and print the output. 
If none of the sum of digits of the elements matches the given number then the sum is 0.

Program:


#include<stdio.h>
int main()
{
int a[100];
int n,t,i,v,x,sum=0,s;
printf("Enter the no of elements in the array : ");
scanf("%d",&n);
printf("\n\nEnter %d elements : ",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\n\nEnter a number : ");
scanf("%d",&t);
for(i=0;i<n;i++)
{
v=a[i];
s=0;
while(v>0)
{
x=v%10;
s=s+x;
v=v/10;
}
if(s==t)
{
sum=sum+a[i];
}
}
printf("\n\nThe sum of elements in the array that has the sum of its digits equal as the given number is : %d",sum);
return 0;
}


Output:














Thank You ...





C Code 33 _ find the sum of STABLE and UNSTABLE elements in the array and show their difference

C Code 33 _ find the sum of STABLE and UNSTABLE elements in the array and show their difference


Problem:


Given a array of integers and their size,
find the sum of STABLE and UNSTABLE elements in the array and
show their difference.

Sample Input:

5
11 50 112 22 111

Sample Output:  

stable=11 50 22 111
unstable=112
difference=82


Explanation:

STABLE-numbers with equal number of each digit-a number in which frequency of digits are equal.
example:-
112233 is a stable number since,
        1 occurs twice , 2 occurs twice so does 3
        i.e all digits in a given number must have equal frequencies
        Similarly,
123 (1,2,3 each occur once)
355533 (3,5 each occur thrice)
are STABLE NUMBERS.
**************************************************
8892 is not a stable number(UNSTABLE),(8's frequency 2, 9 & 2 frequency 1)
Similarly,
2122(2 occurs thrice,1 only once)
5667(6 occurs twice where as 5 & 7 occur only once)
are UNSTABLE NUMBERS.


Program:


#include<stdio.h>
bool isStable(int n)
{
int freq[10],Freqf[10];
//freq-to find the frequency of each digit
for(int i=0;i<10;i++)
freq[i]=Freqf[i]=0;
while(n!=0)
{
freq[n%10]++;
n/=10;
}
for(int i=0;i<10;i++)
{  
if(freq[i]==0)
continue;
Freqf[freq[i]]++;
//Freqf-to find the frequency of frequency
}
for(int i=0;i<10;i++)
{
if(Freqf[i]>0)
n++;
if(n>1)
return 0;    
}
return 1;
}
int main()
{
int size,inp[15],diff=0,stable[15],unstable[15],i,k,j;
scanf("%d",&size);
for(i=k=j=0;i<size;i++)
{
scanf("%d",&inp[i]);
if(isStable(inp[i]))
{
diff+=inp[i];
stable[k++]=inp[i];
}
else
{
diff-=inp[i];
    unstable[j++]=inp[i];
    }
}
printf("\nstable=");
for(i=0;i<k;i++)
printf("%d ",stable[i]);
printf("\nunstable=");
for(i=0;i<j;i++)
printf("%d ",unstable[i]);
printf("\ndifference=%d",diff);
}



Output:













Thank You ...

* * * * * * * The above Program is contributed by AjayRam KV * * * * * * * *

C Code 32 _ To Find p or r Values in nPr Permutation Problem


C Code 32 _ To Find p or r Values in nPr Permutation Problem 

permutations:

Formula to find p is

p(n,r) =   n! / (n-r)!


Program:


#include<stdio.h>
int main()
{
                int n=0,r=0,p=0,i,ch,u=1,l=1;;
                printf("* * * * * nPr Problems on Permutations * * * * *");
                printf("\n\n1 - To find p\n\n2 - To find r\n\nEnter your choice : ");
                scanf("%d",&ch);
                switch(ch)
                {
                case 1:  printf("\n\nEnter the n value : ");
                                                scanf("%d",&n);
                                                printf("\n\nEnter the p value : ");
                                                scanf("%d",&p);
                                                i=n;
                                                while(p>1)
                                                {
                                                                p=p/i;
                                                                i=i-1;
                                                                r=r+1;
                                                }
                                                printf("\n\nThe value of r is : %d",r);
                                                break;
               
                case 2: printf("\n\nEnter the n value : ");
                                                scanf("%d",&n);
                                                printf("\n\nEnter the r value : ");
                                                scanf("%d",&r);
                                                for(i=n;i>=1;i--)
                                                {
                                                                u=u*i;
                                                }
                                                for(i=n-r;i>=1;i--)
                                                {
                                                                l=l*i;
                                                }
                                                p=u/l;
                                                printf("\n\nThe value of p is %d",p);
                                                break;
                                               
                default:
                                                printf("\n\nEnter either 1 or 2 only");
                }
                return 0;
}




Output:











Thank You ...




 

Java Code 3 _ Two - digit " Reduced Subtracted Form " [Wipro Interview Question]

Java Code 3 _ Two - digit  " Reduced Subtracted Form " [Wipro Interview Question] 


Question:

Given a number , you are expected to find its two digit "Reduced Subtracted Form ( RSF) "

The RSF of a number can be found by concatenating the difference between its adjacent digits.

To find two - digit "Reduced subtracted form ( RSF )" , we need to continue this process till the resultant RSF is not a two digit number . 

example :


input number : 6928

(6 - 9) is 3 
(9 - 2) is 7
(2 - 8) is 6

so the reduced RSF of 6928 is 376

(3 - 7) is 4
(7 - 6) is 1

so the reduced RSF of 376 is 41

so the output :

376
41 


Note: 

input number >= 100 .
while concatenating the differences use the absolute value(non negative value).


Program:


package numsub;
import java.util.Scanner;
public class NumSub
{
    static int subtractor(int n)
    {
        int result=0,temp,temp1,diff,pow=1;
            while(n>9)
            {
                temp=n%10;
                temp1=(n/10)%10;
                diff=(temp<temp1)?(temp1-temp):(temp-temp1);//Math.abs(temp1-temp)
                result=result+diff*pow;
                pow*=10;
                n/=10;
            }
            return result;
    }
    public static void main(String[] args)
    { 
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        if(n>99)
        {
           while(n>99)
           {
           n=subtractor(n);
           System.out.println(n);
           }
        }
        else
        System.out.println(n); 
    }
}



Output:








Thank You ...


*********   The above code is contributed by AjayRam KV  *********



Java Code 2 _ To Print the Heart Shaped Pattern using *

Java Code 2 _ To Print the Heart Shaped Pattern using *


Program:


import java.util.*;
public class Main
{
public static void main(String[] args)
{
    Scanner s=new Scanner(System.in);
    int n;
    System.out.println("Enter n value:");       
    n=s.nextInt();                           // To Get 'n' value
   for(int i=n/2;i<=n;i+=2)
          {
               for(int j=1;j<n-i;j+=2)
              {
                  System.out.print(" ");
               }
               for(int j=1;j<=i;j++)
               {
                   System.out.print("*");
               }
               for(int j=1;j<n-i;j++)
               {
                  System.out.print(" ");
               }
                for(int j=1;j<=i;j++)
              {
                  System.out.print("*");
               }
               System.out.println();
         }
         for(int i=n;i>=1;i--)
         {
               for(int j=i;j<n;j++)
               {
                    System.out.print(" ");
                }
                for(int j=1;j<=(i*2)-1;j++)
               {
                   System.out.print("*");
                }
               System.out.println("");
         }

      }
}


Output:








Thank You ...


**************** The Above code is contributed by Madhaneeswaran P *********************

Java Code 1 _ To Find the unique elements in an array

Java Code 1 _ To Find the unique elements in an array


Program:


import java.util.*;
public class Main
{
public static void main(String[] args) 
{
Scanner s=new Scanner(System.in);
int i,j,n,count;
int freq[]=new int[100];
// Get size of the array
System.out.println("Enter size of the array:");
        n=s.nextInt();
        int arr[]=new int[n];
        // Enter array elements
        System.out.println("Enter the array elements:");
        for(i=0;i<n;i++)
       {
             arr[i]=s.nextInt();
             freq[i]=-1;
        }
       // Find frequency of each element in the array
       for(i=0;i<n;i++)
      {
            count=1;
            for(j=i+1;j<n;j++)
           {
                 if(arr[i]==arr[j])
                {
                           count++;
                           freq[j]=0;
                 }
           }
           if(freq[i]!=0)
          {
                 freq[i]=count;
           }
     }
    // Print the unique elements
    System.out.println("Unique elements in the array are:");
    for(i=0;i<n;i++)
    {
          if(freq[i]==1)
         {
              System.out.println(arr[i]+" ");
          }
    }
      }
}



Output:








Thank You ...


**********   The above program is contributed by Madhaneeswaran P    *************



What is VPN

What is VPN ?

  • VPN stands for Virtual Private Network.
  • VPN is a service which is provided  by some third parties to access the web privately and safely.
  • As we said VPN is used to access web safely and privately,but how?
  • Before we know how VPN works we have to know how a normal webpage request works.
  • If you go through our previous post you will understand how the request is processed.
Link :https://iamafutureprogrammer.blogspot.com/2019/08/browsing-webworking.html

  • when you want to visit a webpage called www.abcd.com ,your request will be routed to the respective webserver on which the website is hosted.
  • In the process of routing ,the request packet has the detail of the ip address from which the request is made (if you want to know about ip address visit by previous post ,Link :https://iamafutureprogrammer.blogspot.com/2019/08/what-is-ip-adress.html ) and the each router that routes the request also stores the ip address and the destination webpage address for easy routing of further request from the source.
  • Here you can find our that your identity is exposed on the web now.
  • To avoid exposing yourself on the web vpn is used.


How VPN works?

  • when the request is made from the source the request is forwarded to the vpn server and from the vpn server the request is made to the corresponding webserver and the response is redirected by the vpn server to the source node.
  • here you can see that the vpn servers ip address is only know on the web and the user remains anonymous.

when you can use vpn?
  • suppose a website is blocked in your region(e.g : if website www.abc.com is blocked in India) then if you want to access the website you can use vpn by setting up your vpn server to some country where the website is available(e.g : if that site is available in France then you set your vpn server to France).
  • when you are having a highly confidential documents and want to send to a person over web,then you can use vpn to privately send it through the virtual private network.
  • In a local area network, such a school network or college network  there may me no access to social media sites. here you can use vpn to bypass the constraints.
  • using vpn encrypts your data on the travel over the internet.
  • you can use vpn for accesing torrents.
Some of the free VPN provoiders are,
  • tunnelbear
  • turbovpn
  • windscribe
  • hide.me
  • surfeasy
  • proton vpn
  • hotspot shield free vpn   etc....
There are separate  vpn providers for mobile phones and PC's.

There are both paid and free vpn services,but some extra features are there in paid vpn services.





You can read my previous blogs at  https://iamafutureprogrammer.blogspot.com/

Thankyou......

What is MAC Address

What is MAC Address?

  • MAC stands for Media Access Control.
  • A MAC Address uniquely identifies each device on a network.
  • No two devices in the world cannot have same MAC address.
  • MAC address is a six byte hexadecimal number that is burned in to every NIC by its manufacturer.
  • MAC address is also called as physical address .where as IP address is called as a logical address. 
What is NIC ?
  • NIC stands for Network Interface Card.
  • Network Interface Card is a hardware component(circuit board or a chip) which is used by a node to connect to a network.
  • There are various types of NIC .They are as follows,
                 1 . wireless NIC - they are for wifi connection.
                 2.  wired NIC - they are for Ethernet connection.
                 3.  USB NIC - they are the the devices plugged in to the                                           usb port.

The above picture is how a wired NIC card looks like.

The above picture is how a wireless NIC card looks like.

The above picture is how a USB wireless NIC card looks like.

  • Each of these NIC cards have a six byte address embedded with it by its manufacturer.
How to find out your MAC address on windows laptop or pc ?
  • open command prompt and type the command " ipconfig /all "
  • then you can see a list of items displayed ,in it find physical address .that physical address similar to " 00-21-97-AD-29-A5" is your MAC address.
  • it contains numbers and alphabets only from A to F.


The MAC address is broken up in to two parts 
                                  "00-21-97-AD-29-A5"
  • The first three bytes of the MAC address identifies the manufacturer of the NIC card .(e.g: netgear ,linksys etc..)
  • The last three bytes are unique number from the manufacturer.It uniquely identifies each device on a network.
What is ARP ?
  • ARP stands for Address Resolution Protocol .
  • ARP is a protocol which is used to map the ipaddress of a node with its corresponding MAC address in a network.
We can use MAC address to identify nodes only with in a network.
We cannot use MAC address to transfer data packets over another network.
  • If you have a laptop you will have wifi and also ethernet port.There will be separate MAC address for both of it.
  • If you are connected to network using wifi then you use the your wifi NIC card address as your MAC address ,otherwise if you connected through ethernet port then you use your Ethernet NIC card address as your MAC address.


Note : to read my other posts go to  https://iamafutureprogrammer.blogspot.com/ 
Thank you......



What is an Internet Protocol

What is an Internet Protocol?

We all know that computers can understand only Binary language but human finds it difficult to understand Binary language.


  • A protocol can be explained as it is a digital language through which we communicate with each other over the Internet.
  • It is also called as the set of mutually accepted and implemented rules at the both ends of a communication channel. 
  • That is all the computers should follow a common set of rules if it want to perform any communication with other node.
  • Example : if person A want to convey his idea to person B then both A and B should know a common communicating medium i.e. language. The communication becomes successful only when both of them knows a language in common,that language can be English,Tamil or any other language.
  • Here the language refers to protocol,it should be known to sender as well as the receiver.
  • Internet cannot be with out the Protocols.
Before we see about protocols we need to know about Layers of Network,
  • The International Organization of Standardization (ISO) has developed a standard called Open Systems Interconnections (OSI) .
  • It is a seven layer architecture.
  • Whenever a person want to send and receive messages throughout the globe these 7 layers work together to achieve this.

Now lets customize the 7 layers in to 5 layers as follows to understand the concept easily,
  • Application layer
  • Transport layer
  • Internet layer
  • Link layer
  • Physical layer
lets consider a example of sending a message.
  • The message the sender sends pass through this layers from top to bottom ,when it comes out of the last layer it will be as the packets.(the message is divided in to number of packets).

  1. Application layer:  we uses the application layer to send the message.The protocols used in this layer are HTTP , FTP , DNS etc..
  2. Transport layer:  This layer makes the messages in to data blocks(packets). The protocols used in this layer are TCP and UDP.
  3. Internet layer :  This layer  is used to deliver the data packets.The protocols used are IP , ICMP etc..
  4. Link layer :    The packets are delivered through the link as frames.It is through ethernet , switches or bridges.
  5. Physical layer:  It is the basic hardware of our computer network. it includes coax , Fibre , hubs ,repeaters ,wireless etc..
The senders message passes through this layers from layer 1 to 5 on sender side and on the receiver side it takes the reverse order layer 5 to 1 to recreate the senders original message.

Note : lets discuss about each protocols in the next post on Internet Protocols explained....
If you have any queries ask in comment section below..

For more posts visit my blog : https://iamafutureprogrammer.blogspot.com/
Thank you...

Popular Posts