

Python Tutorial to learn Python programming with examples
Complete Python Tutorial for Beginners Playlist :
Python Tutorial in Hindi :
Github :-
Editing Monitors :
Check out our website:
Follow Telusko on Twitter:
Follow on Facebook:
Telusko :
Navin Reddy :
Follow Navin Reddy on Instagram:
Subscribe to our other channel:
Navin Reddy :
Telusko Hindi :
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
//Can't we do this sir??
arr = [12,24,36,49,51]
num = int(input("Enter the number to search in the list: n"))
for i in arr:
if i==num:
print("number found");
else:
print("number not found");
my assignment:
at = 0
def linerSearch(lst,n):
for b in range(len(lst)):
if lst[b] == n:
globals()['at'] = b
return True
else:
return False
lis = [5,6,7,8,9]
num = 9
if linerSearch(lis,num):
print("found",at+1)
else:
print("not found")
pos=-1
def search(lis,n):
i=0
for i in range(len(lis)):
if lis[i]==n:
globals()['pos']=i
return True
i+=1
return False
lis=[0,99,12,33,45]
n=int(input('Enter number'))
if search(lis,n):
print('Found',pos)
else:
print('Not found')
pos=-1
def search(list, n):
i = 0
for i in range(len(list)):
if list[i] == n:
globals() ['pos']=i
return True
i = i + 1
return False
list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
n = 10
if search(list, n):
print('found at',pos+1)
else:
print('not found')
is it necessary to assign -1 to pos ??
l=[1,2,3,45,65,6,7,8,9,97,61]
m=int(input("value to serch "))
k=-1
def search(list,n):
j=0
for i in list:
j+=1
if i==n :
globals()["k"]=j+k
return True
return False
if search(l,m) == True:
print("found in index number " ,k )
else:
print("not found")
without function with an in-buit function
arr=[3,5,7,4,9]
x=int(input("Enter the number:>"))
for i in arr:
if i == x:
print(arr.index(i)+1)
break
else:
print("Not in the list")
Decided to avoid needing a global variable:
def search(list,n):
for i in list:
if i==n:
pos=list.index(i)
return True, pos
return False, False
list = [5,8,4,6,9,2]
n=9
result, pos = search(list,n)
if result:
print("Found at position",pos+1)
else:
print("Not found")
Sir, What if i have multiple "9(search key" ) in the list
Please advice the best way. i have tried the following,
def search(List , n):
i = 0
while i < len(List):
if n == List[i]:
print(n, "Found in the positon", i)
i=i+1
return False
List = [5, 6, 8, 4, 6, 9, 6]
se = 6
search (List, se)
marks = [35, 50, 60, 70]
n = 70
def search(marks, n):
for i in marks:
if i == n:
return True
return search
if search(marks, n):
print("found", marks.index(n))
else:
print("not found")
SIR plz check this …
my_list = [1, 6, 4, 2, 5, 7, 8]
num = int(input('Find a number between 0-10: '))
for item in my_list:
if item == num:
print('Element Found')
print('Element is on', my_list.index(item)+1, 'Position')
break
else:
print('Not Found')
For user defined:
def search(list,n):
for i in list:
if i==n:
print("value found at: ", list.index(i)+1)
return True
return False
list=[3,7,4,6,9,2]
n=int(input("Enter the number you want to search: "))
if search(list,n):
pass
else:
print("not found")
Sir please make videos on link list using python
pos = -1
def search(nums,n):
x = len(nums)
for i in range(x):
if nums[i]==n:
globals()['pos'] = i
return True
return False
nums = [10,5,9,8,2,7,6,4,3,1]
n = 2
if search(nums,n):
print("Number",n,"nfound at",pos+1)
else:
print("Not found!!!!")
def check (list,n):
a = len(list)
for i in range(a):
if list[i] == n:
return True
return False
list = [1,2,3,4,5]
n = 6
if check (list,n):
print('matching')
else :
print('does not match')
Is it correct sir ?
list=[3,5,76,565,4453,2,2]
n=2
def search(list,n):
for i in list:
if i==n:
print(f"number find at position {list.index(i)}")
break
else:
print("not find")
search(list,n)
y=0
def search(list,n):
for i in range(0,len(list)):
globals()['y']=i
if list[i]==n:
return True
else:
return False
list=[23,87,90,45,67]
n=int(input("Enter the value"))
if search(list,n):
print(n ,"Number found at ",y+1)
else:
print("Number not found")
list = [4, 9, 7, 3, 2, 8]
n = 9
for i in list:
if i == n:
print("Found at ", list.index(i))
break
else:
print("Not Found")
def search(list, n):
global i
i = 0
while i < len(list):
if list[i] == n:
return True
i += 1
return False
list = [4, 9, 7, 3, 2, 8]
n = 7
if search(list, n):
print("Found at",i)
else:
print("Not Found")
……………..# FOR LOOP SOLUTION…………..
pos=1
def search(list,n):
for i in list:
if i==n:
globals()['pos']=i
return True
return False
list=[1,2,3,4,5,6,7,8,9]
n=9
if search(list,n):
print('found at', pos)
else:
print('not found')
What is the need of return false, the code is working fine without writing return false
"pos" here is short for "position"?
def search(list, n):
for i in list:
if i == n:
print("Found {} on index number {}".format(n, list.index(n)))
break
else:
print("{} not found in the given list".format(n))
lst = [1, 3, 4, 5, 6, 7, 9]
search(lst, 10)
def search(l1,n):
for i in range(len(l1)):
if n==l1[i]:
print("found at index {}".format(i))
a=list(map(int,input("Enter numbers in list").split()))
b=int(input("Enter the number you wanna search"))
search(a,b)
def search(List, n):
for i in List:
if i == n:
return True
# ——————————————————–
arr = [5, 8, 4, 6, 9, 2]
x = int(input('Enter a number to look for in the list: {} : '.format(list(arr))))
if search(arr, x):
print(f'Found it!. The value {x} is in position: {arr.index(x)}')
else:
print('Oops, that value is not in the list.')
i am not able to find the pos for 1st number
using for loop
pos=0
def element(li,n):
for i in range (len(li)):
if li[i] == n:
globals()["pos"]=i
return True
return False
li=[1,2,3,4,5]
n=3
if element(li,n):
print("element found at",pos+1)
else:
print("element not found")
def search(li, n):
for i in li:
if i == n:
return True
return False
li = [1, 2, 3, 4, 5, 6, 7, 8]
n = 10
if search(li, n):
print("Found at", li.index(n))
else:
print("Not found")
ind=-1
def search(lis,n):
count=-1
for i in lis:
count+=1
if i==n:
globals()['ind']=count
return 1
return 0
lis=[2,3,4,5,6]
n=5
if search(lis,n):
print("found",ind)
else:
print("not found")
l=[1,2,3,4,5]
n=int(input())
for i in range(len(l)):
if l[i]==n:
print("found",i,"position")
break
else:
print("not found")
for i in listval:
if listval[i]==n:
return true
return False
Using for loop:
pos=-1
def search(list, n):
for i in range(len(list)):
if list[i]==n:
globals ()['pos'] = i
return True
i=i+1
return False
list=[? , ? , ? , ? , ?]
n=?
if search(list, n):
print("found at ", pos)
else:
Print("not found")
🙂
a=int(input('enter the number you want to search :'))
index=1
def lin_learch(list,n):
l=1
for i in list:
if i==n:
return True
break
else:
l+=1
globals()['index']=l
else:
return False
list=[12,10,9,33,11,16]
if lin_learch(list,a):
print('Found')
print('found at position',index)
else:
print('Not Found')
Output:-
enter the number you want to search :11
Found
found at position 5
List=[••••••••]
For n in range():
If list[n]== query?
Print('found',[n])
Thank you Navin …you made my day ….you are a champion mate and appreciate the work that is helping thousands ….
pos = -1
class Search:
def __init__(self,lst,n):
self.lst = lst
self.n=n
print("Initialized the values")
print("search value n is : {} and list is {}".format(n,lst))
def search(self):
for i in range(len(self.lst)):
if(self.n==self.lst[i]):
globals()["pos"] = i+1
return True
return False
lst = [1,3,56,78,99,45,86,43]
n=int(input("Enter the number you want to find :"))
srchobj = Search(lst,n)
if(srchobj.search()):
print("Search found ")
print("Position is {}".format(pos))
else:
print("Not found and try different number")
list=[7,4,9]
n=10
def search():
for i in list:
if i==n:
print("We found")
break
else:
print("not found")
search()
output:not found
Can we do liner search like this , Please let me know
why did he take position as -1?
n=int(input("enter the length of list: "))
list=[]
for i in range(n):
r=int(input(f"enter {i+1} th element: "))
list.append(r)
print(list)
u=int(input("enter a number you need to search for: "))
for i,j in enumerate(list):
if list[i]==u:
print(f"the element {u} found at {i} th location")
break
else:
print("not found")
Sir help me out …
I got struck…
It's giving error telling that 'list' object is not callable
list=[4,3,12,34,56,77,89]
n=int(input('enter a number'))
for i in range(len(list)):
if list[i]==n:
print('found at pos',i+1)
break
else:
print('not found')
def find(lst,value):
n = 0
for i in lst:
n = n + 1
if i == num:
print('Value found',n)
break
else:
print('we didnt find any value')
# Solved by : Atikul Islam Mithu
pos = -1
def search(list,n):
for i in range(len(list)):
if list[i] == n:
globals()['pos'] = i
return True
return False
list = [1,2,5,9,7,4,3]
n = int(input("Enter an element for search : "))
if search(list,n):
print(n,"Found at",pos)
else:
print("Not Found")
POS=-1
def search (List, n):
for i in List:
if i==n:
global ['POS'] = i
return True
return False
List=[2,3,5,8,4,9,1]
n=8
If search(List,n):
print ("Found at", POS+1)
else:
print ("Not Found")
pos=-1
def Linear_Search(lst,ele):
i=0
for i in range(len(lst)-1):
if lst[i]==ele:
globals()['pos']=i+1
return True
return False
lst=[]
size=int(input("Enter the size of list:"))
for i in range(size):
x=int(input("Enter values:"))
lst.append(x)
ele=int(input("Enter the element to be search:"))
if Linear_Search(lst,ele):
print("Found at",pos)
else:
print("Not Found")