Python Program for Finding Maximum Number Of Handshakes

Maximum Number Of Handshakes in Python

Here, in this page we will discuss the program to find the maximum number of handshakes in python.

For the number of handshakes to be maximum, every person should handshake with every other person in the room i.e. all persons present should shake hands.

Maximum number of handshakes in python

Approach :

For the number of handshakes to be maximum, every person should hand-shake with every other person in the room

i.e. all persons present should shake hands.

  • For the first person, there will be N-1 people to shake hands with
  • For second person, there will be N -1 people available but as he has already shaken hands with the first person, there will be N-1-1 = N-2 shake-hands
  • For third person, there will be N-1-1-1 = N-3, and So On…

Therefore the total number of handshake   =   ( N – 1 + N – 2 +….+ 1 + 0 )   =   ( (N-1) * N ) / 2.

Algorithm

  • For N = 8
  • handshakes  =  ( (N-1) * N ) / 2  =  ( 8 x 7 )/2  =  28
  • Print Result
Maximum number of handshakes

Python Code

Run
# number of people
N = 30

# formula
no_of_handshakes = int(N * ((N - 1) / 2))

# print number of handshakes
print('Maximum number of handshakes possible for', N, 'pople are', no_of_handshakes)

Output

Maximum number of handshakes for 30 people are 435

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

4 comments on “Python Program for Finding Maximum Number Of Handshakes”


  • Abhishek

    #Try This
    # Maximum Number Of Handshakes

    n=int(input(“Enter number of persons: “))
    s=0
    for i in range(1,n+1):
    s+=(n-i)
    print(s)


  • MYTHILIESVARAN

    java program for maximum number of handshake of people */
    import java.util.Scanner;
    public class Main{
    public static void main(String [] args)
    {
    Scanner input=new Scanner(System.in);
    System.out.println(” Enter the number of people for calculating number of handshake:”);
    int num=input.nextInt();
    int Total=num*(num-1)/2;
    System.out.println(“Total number of handshake is : “+Total);
    }
    }


  • Deepak

    /*java program for maximum number of handshake of people */
    import java.util.Scanner;
    public class Main{
    public static void main(String [] args)
    {
    Scanner input=new Scanner(System.in);
    System.out.println(” Enter the number of people for calculating number of handshake:”);
    int num=input.nextInt();
    int Total=num*(num-1)/2;
    System.out.println(“Total number of handshake is : “+Total);
    }
    }