Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyClassLinSearch
#python 3.6.9 #PyClassLinSearch: example linear search using a class in Python #this code is created by Rezaul Hoque on April 18,2022; #contact: jewelmrh@yahoo.com; Dhaka, Bangladesh,https://rezaulhoque.wordpress.com;https:hoquestake.blogspot.com #note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; class Search: def __init__(self): self.thelist=[ ] def add(self,element): self.thelist.append(element) def linsearch(self,thelist,item): sz=len(self.thelist) for s in range(sz): if self.thelist[s]==item: return s return -1 def display(self): print(self.thelist) k=Search() c=Search() k.add(1) k.add(2) k.add(3) c.add('A') c.add('Z') c.add('Y') k.display() c.display() item=int(input("Enter item you look for:\n")) a=k.linsearch(k,item) if(a==-1): print("item is not found") else: print("item is found at",a) item2=(input("Enter character you look for:\n")) str=c.linsearch(c,item2) if(str==-1): print("item is not found") else: print("item is found at",str)
run
|
edit
|
history
|
help
0
An attempt at making an encrypting algo in Python.
Rhymes child
quiz1
f strings 3
Regular falsi
hahahah
linked_lists
Emails_Python
Depth First Search - Find if path exists
Removing punctuation from strings