Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def linearSearch(intList,target):
- found = False
- position = 0
- while position < len(intList) and not found:
- if intList[position] == target:
- found = True
- position = position + 1
- return found
- linearList = [3,5,9,7,6,12,15,9,1]
- numInput = input("What number are you looking for? ")
- numFound = linearSearch(numInput, linearList)
- if numFound:
- print("The number is in index: ")
- else:
- print("The number is not in the list")
- def linearSearch(intList,target):
- #print (target)
- found = False
- position = 0
- while position < len(intList):
- #print(intList[position])
- if intList[position] == target:
- found = True
- break
- position = position + 1
- return found
- linearList = [3,5,9,7,6,12,15,9,1]
- numInput = int(input("What number are you looking for? "))
- numFound = linearSearch(linearList,numInput)
- if numFound:
- print("The number is in index: ")
- else:
- print("The number is not in the list")
- // funtion which rturns true if item found inside list.
- def linearSearch(list, value):
- for i in range(len(list)):
- if i == value:
- return True
- list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- item = 10
- print(linearSearch(list, item)) // item to search
- for x in list:
- if x == str(num):
- print("match found:"+x)
- break
- else:
- print('no match found')
Add Comment
Please, Sign In to add comment