Input a list/tuple of elements, search for a given element in the list/tuple.

numbers=[3,1,6,7,8,4]
size=len(numbers)   #getting size(no of elements) of list
i=0
number=int(input('enter the number to search')) #taking input in string from user and converting to integer
success=False    #flag
while(i<size):
    if(numbers[i]==number):  #comparison
        print('number found at location ',i+1)  #found message
        success=True
        break
   else:
      success=False
   i=i+1
if(success==False):
    print('number not found')
 
Explanation: In this Program we have a list of numbers. we want to search for a particular number in list. it is case of simple searching or linear search in list. we are taking input from user and converting it into integer. using a flag for checking purpose in program.
 
inside while loop we are checking each number in the list with input number to search. if match then printing message and also showing location of number where number found in list. setting the flag to true and exiting(breaking) from loop.
 
if number not found, then we are setting flag to false each time till end or untill number found in the loop. if number is not in the list loop will complete iterations and flag is set to false. after termination of loop number not found message is displayed.