Linear search in python using list

Python program for linear search using list and for loop. Python program first takes the list of all elements as input. After that input element to be found. If the element is present, it shows Element present else not found. This python project is useful for beginners and CBSE KV School Class 11 and Class 12 students computer science practical file and NIELIT O Level module.

WAP to input a list of number and search for a given number using linear search

Python code of program

Linear search in python using list

Explanation of Source code in program

l=eval(input(“Enter the list of numbers”)) # inputs the list of numbers
x=int(input(“Enter the number”)) #inputs the number you want to check
for i in l: # here for loop starts from the first number of the list to the last number of the list
if i==x: # If any of the numbers matching the input to be checking number
print(“Element present”)# If the element is there in list then it shows element present
break # condition is breaking means program is terminating here if element is present
print(“Element not found”) # if it is not present there then it shows Element not Founding.

Output Linear search in python using list

Linear search in python using list

Testing of program

In above shell window, we entered sets of numbers and asked to search for 54. Element is present, therefore out put is Element Present. We test this program with 2 more sets of elements.

Our python program is working.

There are three input with list showing output.

Download source code – click here

For more python programs – click here

Hello World Program in Python

Input a welcome message and display it in Python

Display the larger / smaller number in Python.

Greatest of Three Numbers in Python using Nested if

Patterns using nested loop in Python

Program to Print Pattern in Python

Program to input the value of x and n and sum of series in Python

Python Program for Armstrong, Prefect Number, Palindrome

Program of Prime number by recursion in python

Prime Number Program in Python

Write a Program to Print Fibonacci Series in Python

LCM and GCD program in Python

Python program to count number of vowels in a string

Whether a String is Palindrome or not in Python

Bubble Sort Program in Python

Linear search in python using list

Program to read a text file in python

Python program to read a file line by line

Program to Count Vowels and Consonants in Python

Stack Program in Python

Queue Program in Python

Python Leap Year Program for Beginners

Python Program to Print Series and Addition

Binary Search Program in Python

Program to find sum of digits in python

Sum of numbers divisible by 3 and 5 in python