Guest User

Untitled

a guest
Nov 14th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. def linearSearch(intList,target):
  2. found = False
  3. position = 0
  4. while position < len(intList) and not found:
  5. if intList[position] == target:
  6. found = True
  7. position = position + 1
  8.  
  9. return found
  10.  
  11. linearList = [3,5,9,7,6,12,15,9,1]
  12. numInput = input("What number are you looking for? ")
  13. numFound = linearSearch(numInput, linearList)
  14. if numFound:
  15. print("The number is in index: ")
  16. else:
  17. print("The number is not in the list")
  18.  
  19. def linearSearch(intList,target):
  20. #print (target)
  21. found = False
  22. position = 0
  23. while position < len(intList):
  24. #print(intList[position])
  25. if intList[position] == target:
  26. found = True
  27. break
  28. position = position + 1
  29.  
  30. return found
  31.  
  32. linearList = [3,5,9,7,6,12,15,9,1]
  33. numInput = int(input("What number are you looking for? "))
  34. numFound = linearSearch(linearList,numInput)
  35. if numFound:
  36. print("The number is in index: ")
  37. else:
  38. print("The number is not in the list")
  39.  
  40. // funtion which rturns true if item found inside list.
  41. def linearSearch(list, value):
  42. for i in range(len(list)):
  43. if i == value:
  44. return True
  45.  
  46. list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  47. item = 10
  48. print(linearSearch(list, item)) // item to search
  49.  
  50. for x in list:
  51. if x == str(num):
  52. print("match found:"+x)
  53. break
  54. else:
  55. print('no match found')
Add Comment
Please, Sign In to add comment