SlideShare a Scribd company logo
1 of 31
LIST IN PYTHON
CLASS : XII
COMPUTER SCIENCE(083) PART-4
SEARCHING IN LIST
What is searching?
It is the process of finding the position of a particular
element in a list.
We can do searching in two ways:
Linear search
In linear search, each element or item of list is compared
with the item or value to be searched for, one by one.
It is also known as Sequential search. It works in both
sorted and unsorted list of numbers.
Example Unsorted numbers:
10 15 40 18 29 38 5 37
Example sorted numbers:
10 15 17 18 29 38 45 67
Let’s Understand Linear Search with the help of
Example:
There are six batches in a sequence:
Block:1 Block:2 Block:3 Block:4 Block:5 Block:6
So if user want to find or search batch from the sequence and want its position, where found:
If user want to search Excellent from the batches in a sequence
Block:6
Let’s Understand Linear Search with the help of
Example:
Now in linear search the searching of excellent batch starts from first block to last block:
Block:1 Block:2 Block:3 Block:4 Block:5
So Excellent batch first compare with Block 1 batch:
Is Batch Excellent equal to Amazing. NO
Now its move to the next block that is Block 2
Block:6
Let’s Understand Linear Search with the help of
Example:
Now Excellent compare with Block 2 “Wonderful”
Block:1 Block:2 Block:3 Block:4 Block:5
Is Batch Excellent equal to Wonderful. NO
Now its move to the next block that is Block 3
Block:6
Let’s Understand Linear Search with the help of
Example:
Now Excellent compare with Block 3 “Super”
Block:1 Block:2 Block:3 Block:4 Block:5
Is Batch Excellent equal to Super. NO
Now its move to the next block that is Block 4
Block:6
Let’s Understand Linear Search with the help of
Example:
Now Excellent compare with Block 4 “Brilliant”
Block:1 Block:2 Block:3 Block:4 Block:5
Is Batch Excellent equal to Brilliant. NO
Now its move to the next block that is Block 5
Block:6
Let’s Understand Linear Search with the help of
Example:
Now Excellent compare with Block 5 “Excellent”
Block:1 Block:2 Block:3 Block:4 Block:5
Is Batch Excellent equal to Excellent. Yes
Now its Stop here only and exit from the Sequence(means loop)And Print the message that excellent exist in Sequence.
So now Let Us understand this linear
search with another example
If there is a sequence of numbers in a list
no=[10,15,40,18,29,38,5,37]
Example Unsorted numbers:
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
Now if user enter number 18 to be
searched from a list
18
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
val=
Now we have to search this number in a list no and if
number found then store the index value as the position
of number found.
Pos=-1 It will store the position of the number found or not found
So next is to accept the value from user in a variable val to be searched in a list
Loop starts from first index no 0
(zero) to last index no 7(seven)
18
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
val=
Pos=-1
LOOP
FROM 0 TO 7
Loop AT FIRST INDEX VALUE IS 0
18
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
val=
First value at index no 0(zero) that is 10 compare with val no 18
Pos=-1
Comparison of these values are same NO
If Both values are not same then it move to
next block of the list
Loop AT SECOND INDEX NO 1
18
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
val=
Second value at index no 1(One) that is 15 compare with val no 18
Pos=-1
Comparison of these values are same NO
If Both values are not same then it move
to next block of the list
Loop AT THIRD INDEX NO 2
18
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
val=
Third value at index no 2(Two) that is 40 compare with val no 18
Pos=-1
Comparison of these values are same NO
If Both values are not same then it move to next block of the list
Loop AT FOURTH INDEX NO 3
18
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
val=
Fourth value at index no 3(Three) that is 18 compare with val no 18
Pos=-1 Comparison of these values are same Yes
If Both values are same then it
will stop here and store the index
value inside the pos
Loop starts from first index no 0
(zero) to last index no 7(seven)
18
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
val=
Pos=3 Now pos is 3 on the basis of index number and -1 value is
overwrite with index number where value 18 found . And
then we check that value of pos is positive or negative.
Now let us understand the concept
of Linear search
To understand the linear search first we need to know the steps:
Step 1: Declare the list and initialize it with some values
Step 2: Declare one variable to store the position with -1 and value of pos.
will overwrite when number found in the list.
Step 3: Accept the value to be searched from the user and store in a variable.
Step 4: Start the loop from starting index to the last index no
Step 5: Compare the search no with the list of no.’s one by one using index
no.
Step 6: if no. found pos store the index number and loop will stop there only.
no=[10,15,40,18,29,38,5,37]
Step 1: Declare the list and initialize it with some
values
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
no=[10,15,40,18,29,38,5,37]
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
pos=-1 Step 2: Declare one variable to store the position with -1
and value of pos. will overwrite when number found in
the list.
Pos=-1
no=[10,15,40,18,29,38,5,37]
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
pos=-1
val=int(input(“Enter the value”))
Step 3: Accept the value to be searched from the user and
store in a variable.
no=[10,15,40,18,29,38,5,37]
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
pos=-1
val=int(input(“Enter the value”))
k=len(no)
for x in range(0,k):
Step 4: Start the loop from starting index to the last index
no
no=[10,15,40,18,29,38,5,37]
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
pos=-1
val=int(input(“Enter the value”))
k=len(no)
for x in range(0,k):
Step 5: Compare the search no with
the list of no.’s one by one using index
no.
if no[x]==val:
pos=x
break
no=[10,15,40,18,29,38,5,37]
0 1 2 3 4 5 6 7
10 15 40 18 29 38 5 37
no=
pos=-1
val=int(input(“Enter the value”))
k=len(no)
for x in range(0,k):
if no[x]==val:
pos=x
break
Step 6: if no. found pos store
the index number and loop
will stop there only and if pos
is negative it means number
not found and if positive then
number found
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1)
For loop with range:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
for x in range(0,k):
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1
While loop:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
x=0
while x<k:
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1
Step 1 We declare the list of numbers in a variable no
For loop with range:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
for x in range(0,k):
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1
While loop:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
x=0
while x<k:
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1
Step 2 we set the pos to negative value, if number not found it remains -1
means number not exists in a list
For loop with range:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
for x in range(0,k):
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1
While loop:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
x=0
while x<k:
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1
Next step is to accept the value in a variable val from user to be searched in a
list
For loop with range:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
for x in range(0,k):
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1
While loop:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
x=0
while x<k:
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1
Next find the length of list no and store it inside the variable k.
For loop with range:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
for x in range(0,k):
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1
While loop:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
x=0
while x<k:
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1
Next start the loop that starts from 0 to k means last number.
For loop with range:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
for x in range(0,k):
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1
While loop:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
x=0
while x<k:
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1
Next check the number exists or not using if condition,if yes then loop stop and
pos will store the index number as position.
For loop with range:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
for x in range(0,k):
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1)
While loop:
no=[10,15,40,18,29,38,5,37]
pos=-1
val=int(input(“Enter the value”))
k=len(no)
x=0
while x<k:
if no[x]==val:
pos=x
break
if pos<0:
print(“No. not found”)
else:
print(“No found at pos=“,pos+1)
At last if the pos is still negative it means search number does not exist in a list
and if pos is positive, it means number exists in a list

More Related Content

What's hot

Applied Calculus Chapter 1 polar coordinates and vector
Applied Calculus Chapter  1 polar coordinates and vectorApplied Calculus Chapter  1 polar coordinates and vector
Applied Calculus Chapter 1 polar coordinates and vectorJ C
 
Chapter 3: Linear Systems and Matrices - Part 2/Slides
Chapter 3: Linear Systems and Matrices - Part 2/SlidesChapter 3: Linear Systems and Matrices - Part 2/Slides
Chapter 3: Linear Systems and Matrices - Part 2/SlidesChaimae Baroudi
 
Chapter 3: Linear Systems and Matrices - Part 3/Slides
Chapter 3: Linear Systems and Matrices - Part 3/SlidesChapter 3: Linear Systems and Matrices - Part 3/Slides
Chapter 3: Linear Systems and Matrices - Part 3/SlidesChaimae Baroudi
 
Chapter 3: Linear Systems and Matrices - Part 1/Slides
Chapter 3: Linear Systems and Matrices - Part 1/SlidesChapter 3: Linear Systems and Matrices - Part 1/Slides
Chapter 3: Linear Systems and Matrices - Part 1/SlidesChaimae Baroudi
 
Algebra 2 unit 12.1
Algebra 2 unit 12.1Algebra 2 unit 12.1
Algebra 2 unit 12.1Mark Ryder
 
Chapter 4: Vector Spaces - Part 4/Slides By Pearson
Chapter 4: Vector Spaces - Part 4/Slides By PearsonChapter 4: Vector Spaces - Part 4/Slides By Pearson
Chapter 4: Vector Spaces - Part 4/Slides By PearsonChaimae Baroudi
 
Objective 1 - Identifying Functions
Objective 1 - Identifying FunctionsObjective 1 - Identifying Functions
Objective 1 - Identifying Functionsguestd3e8a33
 
Algebra 2 unit 12
Algebra 2 unit 12Algebra 2 unit 12
Algebra 2 unit 12Mark Ryder
 
Sorting (Bubble,Merge,Selection sort)
Sorting (Bubble,Merge,Selection sort)Sorting (Bubble,Merge,Selection sort)
Sorting (Bubble,Merge,Selection sort)oDesk
 
Matrix presentation By DHEERAJ KATARIA
Matrix presentation By DHEERAJ KATARIAMatrix presentation By DHEERAJ KATARIA
Matrix presentation By DHEERAJ KATARIADheeraj Kataria
 
Pre-Cal 40S Slides January 16, 2008
Pre-Cal 40S Slides January 16,  2008Pre-Cal 40S Slides January 16,  2008
Pre-Cal 40S Slides January 16, 2008Darren Kuropatwa
 
Advanced algebra
Advanced algebraAdvanced algebra
Advanced algebraspark21
 

What's hot (20)

Applied Calculus Chapter 1 polar coordinates and vector
Applied Calculus Chapter  1 polar coordinates and vectorApplied Calculus Chapter  1 polar coordinates and vector
Applied Calculus Chapter 1 polar coordinates and vector
 
Math IA
Math IAMath IA
Math IA
 
Chapter 3: Linear Systems and Matrices - Part 2/Slides
Chapter 3: Linear Systems and Matrices - Part 2/SlidesChapter 3: Linear Systems and Matrices - Part 2/Slides
Chapter 3: Linear Systems and Matrices - Part 2/Slides
 
Chapter 3: Linear Systems and Matrices - Part 3/Slides
Chapter 3: Linear Systems and Matrices - Part 3/SlidesChapter 3: Linear Systems and Matrices - Part 3/Slides
Chapter 3: Linear Systems and Matrices - Part 3/Slides
 
Chapter 3: Linear Systems and Matrices - Part 1/Slides
Chapter 3: Linear Systems and Matrices - Part 1/SlidesChapter 3: Linear Systems and Matrices - Part 1/Slides
Chapter 3: Linear Systems and Matrices - Part 1/Slides
 
Math ia
Math iaMath ia
Math ia
 
Matriks
MatriksMatriks
Matriks
 
Algebra 2 unit 12.1
Algebra 2 unit 12.1Algebra 2 unit 12.1
Algebra 2 unit 12.1
 
Math ia
Math iaMath ia
Math ia
 
Chapter 4: Vector Spaces - Part 4/Slides By Pearson
Chapter 4: Vector Spaces - Part 4/Slides By PearsonChapter 4: Vector Spaces - Part 4/Slides By Pearson
Chapter 4: Vector Spaces - Part 4/Slides By Pearson
 
Objective 1 - Identifying Functions
Objective 1 - Identifying FunctionsObjective 1 - Identifying Functions
Objective 1 - Identifying Functions
 
Algebra 2 unit 12
Algebra 2 unit 12Algebra 2 unit 12
Algebra 2 unit 12
 
Sorting (Bubble,Merge,Selection sort)
Sorting (Bubble,Merge,Selection sort)Sorting (Bubble,Merge,Selection sort)
Sorting (Bubble,Merge,Selection sort)
 
APM.pdf
APM.pdfAPM.pdf
APM.pdf
 
Matrix presentation By DHEERAJ KATARIA
Matrix presentation By DHEERAJ KATARIAMatrix presentation By DHEERAJ KATARIA
Matrix presentation By DHEERAJ KATARIA
 
Final project
Final projectFinal project
Final project
 
Rank of a matrix
Rank of a matrixRank of a matrix
Rank of a matrix
 
Pre-Cal 40S Slides January 16, 2008
Pre-Cal 40S Slides January 16,  2008Pre-Cal 40S Slides January 16,  2008
Pre-Cal 40S Slides January 16, 2008
 
determinants.ppt
determinants.pptdeterminants.ppt
determinants.ppt
 
Advanced algebra
Advanced algebraAdvanced algebra
Advanced algebra
 

Similar to LIST IN PYTHON-PART 4[SEARCHING IN LIST]

Data Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithmsData Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithmsAbdullah Al-hazmy
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3smruti sarangi
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsMohamed Loey
 
sorting and searching.pptx
sorting and searching.pptxsorting and searching.pptx
sorting and searching.pptxParagAhir1
 
Data Structure Searching.pptx
Data Structure Searching.pptxData Structure Searching.pptx
Data Structure Searching.pptxSourabhTaneja4
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptxssuserd602fd
 
Insertion Sort, Quick Sort And Their complexity
Insertion Sort, Quick Sort And Their complexityInsertion Sort, Quick Sort And Their complexity
Insertion Sort, Quick Sort And Their complexityMotaleb Hossen Manik
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queueRai University
 
Computer notes - Binary Search
Computer notes - Binary SearchComputer notes - Binary Search
Computer notes - Binary Searchecomputernotes
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueRai University
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32ecomputernotes
 
Pre algebra help
Pre algebra helpPre algebra help
Pre algebra helpjake8144
 
Sorting and Its Types
Sorting and Its TypesSorting and Its Types
Sorting and Its Typesamberkhan59
 
03 Linear Arrays Memory Representations .pdf
03 Linear Arrays Memory Representations .pdf03 Linear Arrays Memory Representations .pdf
03 Linear Arrays Memory Representations .pdfKkSingh64
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queueRai University
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Muhammad Hammad Waseem
 

Similar to LIST IN PYTHON-PART 4[SEARCHING IN LIST] (20)

Data Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithmsData Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithms
 
UNEC__1683196273.pptx
UNEC__1683196273.pptxUNEC__1683196273.pptx
UNEC__1683196273.pptx
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
 
sorting and searching.pptx
sorting and searching.pptxsorting and searching.pptx
sorting and searching.pptx
 
Chapter3.pptx
Chapter3.pptxChapter3.pptx
Chapter3.pptx
 
Data Structure Searching.pptx
Data Structure Searching.pptxData Structure Searching.pptx
Data Structure Searching.pptx
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
 
Insertion Sort, Quick Sort And Their complexity
Insertion Sort, Quick Sort And Their complexityInsertion Sort, Quick Sort And Their complexity
Insertion Sort, Quick Sort And Their complexity
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
Computer notes - Binary Search
Computer notes - Binary SearchComputer notes - Binary Search
Computer notes - Binary Search
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32
 
Pre algebra help
Pre algebra helpPre algebra help
Pre algebra help
 
Sorting and Its Types
Sorting and Its TypesSorting and Its Types
Sorting and Its Types
 
03 Linear Arrays Memory Representations .pdf
03 Linear Arrays Memory Representations .pdf03 Linear Arrays Memory Representations .pdf
03 Linear Arrays Memory Representations .pdf
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Unit vii sorting
Unit   vii sorting Unit   vii sorting
Unit vii sorting
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
 

More from vikram mahendra

Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemvikram mahendra
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shopvikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMvikram mahendra
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Pythonvikram mahendra
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONvikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONvikram mahendra
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONvikram mahendra
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1vikram mahendra
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2vikram mahendra
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONvikram mahendra
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]vikram mahendra
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONvikram mahendra
 

More from vikram mahendra (20)

Communication skill
Communication skillCommunication skill
Communication skill
 
Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop system
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shop
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEM
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Python
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHON
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHON
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
GREEN SKILL[PART-2]
GREEN SKILL[PART-2]GREEN SKILL[PART-2]
GREEN SKILL[PART-2]
 
GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

LIST IN PYTHON-PART 4[SEARCHING IN LIST]

  • 1. LIST IN PYTHON CLASS : XII COMPUTER SCIENCE(083) PART-4 SEARCHING IN LIST
  • 2. What is searching? It is the process of finding the position of a particular element in a list. We can do searching in two ways:
  • 3. Linear search In linear search, each element or item of list is compared with the item or value to be searched for, one by one. It is also known as Sequential search. It works in both sorted and unsorted list of numbers. Example Unsorted numbers: 10 15 40 18 29 38 5 37 Example sorted numbers: 10 15 17 18 29 38 45 67
  • 4. Let’s Understand Linear Search with the help of Example: There are six batches in a sequence: Block:1 Block:2 Block:3 Block:4 Block:5 Block:6 So if user want to find or search batch from the sequence and want its position, where found: If user want to search Excellent from the batches in a sequence
  • 5. Block:6 Let’s Understand Linear Search with the help of Example: Now in linear search the searching of excellent batch starts from first block to last block: Block:1 Block:2 Block:3 Block:4 Block:5 So Excellent batch first compare with Block 1 batch: Is Batch Excellent equal to Amazing. NO Now its move to the next block that is Block 2
  • 6. Block:6 Let’s Understand Linear Search with the help of Example: Now Excellent compare with Block 2 “Wonderful” Block:1 Block:2 Block:3 Block:4 Block:5 Is Batch Excellent equal to Wonderful. NO Now its move to the next block that is Block 3
  • 7. Block:6 Let’s Understand Linear Search with the help of Example: Now Excellent compare with Block 3 “Super” Block:1 Block:2 Block:3 Block:4 Block:5 Is Batch Excellent equal to Super. NO Now its move to the next block that is Block 4
  • 8. Block:6 Let’s Understand Linear Search with the help of Example: Now Excellent compare with Block 4 “Brilliant” Block:1 Block:2 Block:3 Block:4 Block:5 Is Batch Excellent equal to Brilliant. NO Now its move to the next block that is Block 5
  • 9. Block:6 Let’s Understand Linear Search with the help of Example: Now Excellent compare with Block 5 “Excellent” Block:1 Block:2 Block:3 Block:4 Block:5 Is Batch Excellent equal to Excellent. Yes Now its Stop here only and exit from the Sequence(means loop)And Print the message that excellent exist in Sequence.
  • 10. So now Let Us understand this linear search with another example If there is a sequence of numbers in a list no=[10,15,40,18,29,38,5,37] Example Unsorted numbers: 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no=
  • 11. Now if user enter number 18 to be searched from a list 18 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no= val= Now we have to search this number in a list no and if number found then store the index value as the position of number found. Pos=-1 It will store the position of the number found or not found So next is to accept the value from user in a variable val to be searched in a list
  • 12. Loop starts from first index no 0 (zero) to last index no 7(seven) 18 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no= val= Pos=-1 LOOP FROM 0 TO 7
  • 13. Loop AT FIRST INDEX VALUE IS 0 18 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no= val= First value at index no 0(zero) that is 10 compare with val no 18 Pos=-1 Comparison of these values are same NO If Both values are not same then it move to next block of the list
  • 14. Loop AT SECOND INDEX NO 1 18 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no= val= Second value at index no 1(One) that is 15 compare with val no 18 Pos=-1 Comparison of these values are same NO If Both values are not same then it move to next block of the list
  • 15. Loop AT THIRD INDEX NO 2 18 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no= val= Third value at index no 2(Two) that is 40 compare with val no 18 Pos=-1 Comparison of these values are same NO If Both values are not same then it move to next block of the list
  • 16. Loop AT FOURTH INDEX NO 3 18 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no= val= Fourth value at index no 3(Three) that is 18 compare with val no 18 Pos=-1 Comparison of these values are same Yes If Both values are same then it will stop here and store the index value inside the pos
  • 17. Loop starts from first index no 0 (zero) to last index no 7(seven) 18 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no= val= Pos=3 Now pos is 3 on the basis of index number and -1 value is overwrite with index number where value 18 found . And then we check that value of pos is positive or negative.
  • 18. Now let us understand the concept of Linear search To understand the linear search first we need to know the steps: Step 1: Declare the list and initialize it with some values Step 2: Declare one variable to store the position with -1 and value of pos. will overwrite when number found in the list. Step 3: Accept the value to be searched from the user and store in a variable. Step 4: Start the loop from starting index to the last index no Step 5: Compare the search no with the list of no.’s one by one using index no. Step 6: if no. found pos store the index number and loop will stop there only.
  • 19. no=[10,15,40,18,29,38,5,37] Step 1: Declare the list and initialize it with some values 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no=
  • 20. no=[10,15,40,18,29,38,5,37] 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no= pos=-1 Step 2: Declare one variable to store the position with -1 and value of pos. will overwrite when number found in the list. Pos=-1
  • 21. no=[10,15,40,18,29,38,5,37] 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no= pos=-1 val=int(input(“Enter the value”)) Step 3: Accept the value to be searched from the user and store in a variable.
  • 22. no=[10,15,40,18,29,38,5,37] 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no= pos=-1 val=int(input(“Enter the value”)) k=len(no) for x in range(0,k): Step 4: Start the loop from starting index to the last index no
  • 23. no=[10,15,40,18,29,38,5,37] 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no= pos=-1 val=int(input(“Enter the value”)) k=len(no) for x in range(0,k): Step 5: Compare the search no with the list of no.’s one by one using index no. if no[x]==val: pos=x break
  • 24. no=[10,15,40,18,29,38,5,37] 0 1 2 3 4 5 6 7 10 15 40 18 29 38 5 37 no= pos=-1 val=int(input(“Enter the value”)) k=len(no) for x in range(0,k): if no[x]==val: pos=x break Step 6: if no. found pos store the index number and loop will stop there only and if pos is negative it means number not found and if positive then number found if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1)
  • 25. For loop with range: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) for x in range(0,k): if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1 While loop: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) x=0 while x<k: if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1 Step 1 We declare the list of numbers in a variable no
  • 26. For loop with range: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) for x in range(0,k): if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1 While loop: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) x=0 while x<k: if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1 Step 2 we set the pos to negative value, if number not found it remains -1 means number not exists in a list
  • 27. For loop with range: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) for x in range(0,k): if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1 While loop: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) x=0 while x<k: if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1 Next step is to accept the value in a variable val from user to be searched in a list
  • 28. For loop with range: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) for x in range(0,k): if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1 While loop: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) x=0 while x<k: if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1 Next find the length of list no and store it inside the variable k.
  • 29. For loop with range: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) for x in range(0,k): if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1 While loop: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) x=0 while x<k: if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1 Next start the loop that starts from 0 to k means last number.
  • 30. For loop with range: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) for x in range(0,k): if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1 While loop: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) x=0 while x<k: if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1 Next check the number exists or not using if condition,if yes then loop stop and pos will store the index number as position.
  • 31. For loop with range: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) for x in range(0,k): if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1) While loop: no=[10,15,40,18,29,38,5,37] pos=-1 val=int(input(“Enter the value”)) k=len(no) x=0 while x<k: if no[x]==val: pos=x break if pos<0: print(“No. not found”) else: print(“No found at pos=“,pos+1) At last if the pos is still negative it means search number does not exist in a list and if pos is positive, it means number exists in a list