Program to print the duplicate elements of an Array in Python.

Program to print the duplicate elements of an Array in Python. This program contains input, print functions, for loop and if else conditional statement. This is for beginners, class 11,12 and B Tech computer science students.

Program to print the duplicate elements of an Array in Python

What is duplicate elements ?

The element which is present more than one in the given Array.

What is an Array?

An array is a collection of similar data elements stored at contiguous memory locations.

Source code :

#Enter the length of Array
n= int(input("Enter the length of Array"))
#Intialising a array
a=[None]*n
#running a for loop for the enter of array
for i in range (0,n):
    m= int(input( " Enter the content of Array")) 
    a[i]=m
#for checking the n.o of times a number occuring in an array
for i in range (0,n):
    #print (a[i])
    count=0
    
    for j in range (0,n):
        if a[i]==a[j]:
            count= count+1
    if (count>1):
        print(a[i]," duplicate n.o of times",count)

Source code Explanation :

step 1: Enter the length of Array
n= int(input(“Enter the length of Array”))
step 2: Intialising a array
a=[None]*n
step 3: running a for loop for the enter of array
for i in range (0,n):
m= int(input( ” Enter the content of Array”))
a[i]=m
step 4: for checking the n.o of times a number occuring in an array
for i in range (0,n):
count=0
for j in range (0,n):
if a[i]==a[j]:
count= count+1
if (count>1):
print(a[i],” duplicate n.o of times”,count)

Output :

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
 RESTART: C:/csstudy/source code file 2/Python program to print the duplicate elements of an array.py 
Enter the length of Array6
 Enter the content of Array2
 Enter the content of Array2
 Enter the content of Array3
 Enter the content of Array6
 Enter the content of Array5
 Enter the content of Array2
2  duplicate n.o of times 3
2  duplicate n.o of times 3
2  duplicate n.o of times 3
>>> 

Output explanation:

Type “help”, “copyright”, “credits” or “license()” for more information.RESTART: C:/csstudy/source code file 2/Python program to print the duplicate elements of an array.py
Enter the length of Array6
Enter the content of Array2
Enter the content of Array2
Enter the content of Array3
Enter the content of Array6
Enter the content of Array5
Enter the content of Array2
2 duplicate n.o of times 3
2 duplicate n.o of times 3
2 duplicate n.o of times 3

Length of the Array is asked.
content of array is entered.
The number of duplicate number is shown and also their frequency.

Conclusion:

The program works fine.

Thank you for reading, learning and downloading Program to print the duplicate elements of an Array in Python. This program contains input, print functions, for loop and if else conditional statement. This is for beginners, class 11,12 and B Tech computer science students. For more practice of question click below on the links:
Python Programs Archives – CS Study
Computer Science with Python Practical Book Solutions Class 11 Term -2 – CS Study
Computer Science Practical file for class 12 Term-2 – CS Study
Python Projects for Class 12 with Source Code (Mysql Connectivity) – CS Study

Leave a Comment

Your email address will not be published.