2016-07-22 17:04:54 +00:00
|
|
|
|
2016-07-29 19:14:30 +00:00
|
|
|
def sequential_search(alist, target):
|
2016-07-29 19:31:20 +00:00
|
|
|
for index, item in enumerate(alist):
|
|
|
|
if item == target:
|
|
|
|
print("Found target {} at index {}".format(target, index))
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
print("Not found")
|
2016-07-29 19:14:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2016-07-29 19:31:20 +00:00
|
|
|
try:
|
|
|
|
print("Enter numbers separated by spaces")
|
|
|
|
s = raw_input()
|
|
|
|
inputs = list(map(int, s.split(' ')))
|
|
|
|
target = int(raw_input('\nEnter a single number to be found in the list: '))
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
else:
|
|
|
|
sequential_search(inputs, target)
|
2016-07-29 19:14:30 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-07-29 19:31:20 +00:00
|
|
|
print('==== Linear Search ====\n')
|
|
|
|
main()
|