FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonprogram/Linear Search at master · RitikPyCode/pythonprogram · GitHub
RitikPyCode
pythonprogram
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonprogram
/
Linear Search
Copy path
More file actions
More file actions
Latest commit
History
History
History
18 lines (15 loc) · 503 Bytes
Breadcrumbs
pythonprogram
/
Linear Search
Copy path
File metadata and controls
18 lines (15 loc) · 503 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def linear_search(alist, key):
"""Return index of key in alist. Return -1 if key not present."""
for i in range(len(alist)):
if alist[i] == key:
return i
return -1
alist = input('Enter the list of numbers: ')
alist = alist.split()
alist = [int(x) for x in alist]
key = int(input('The number to search for: '))
index = linear_search(alist, key)
if index < 0:
print('{} was not found.'.format(key))
else:
print('{} was found at index {}.'.format(key, index))
Back
|
FazBrowse Home
|
New Git URL