From 5db83095b3f3b4d2d9bef80a94a12acba13f5345 Mon Sep 17 00:00:00 2001 From: Chetan Kaushik Date: Fri, 22 Jul 2016 22:34:54 +0530 Subject: [PATCH] Linear Search --- LinearSearch.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 LinearSearch.py diff --git a/LinearSearch.py b/LinearSearch.py new file mode 100644 index 000000000..12117896c --- /dev/null +++ b/LinearSearch.py @@ -0,0 +1,28 @@ +def search_linear(x,y): + n = len( x ) + for i in range(n): + if theValue[i] == y: + return True + return false + +def sequentialSearch(alist, item): + pos = 0 + found = False + + while pos < len(alist) and not found: + + if alist[pos] == item: + found = True + print("Found") + else: + pos = pos+1 + if found == False: + print("Not found") + return found + +print("Enter numbers seprated by space") +s = input() +numbers = list(map(int, s.split())) +trgt =int( input('enter a single number to be found in the list ')) +sequentialSearch(numbers, trgt) +