Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def linearSearch(query, sequence):
- found = False
- for position, item in enumerate(sequence, 1):
- if item == query:
- print("Found " + str(query) + " at position " + str(position))
- found = True
- if found == False:
- print("The number " + str(query) + " was not found.")
- return found
- def linearSearchWhile(query, sequence):
- found = False
- position = 0
- while found == False and position < len(sequence):
- if sequence[position] == query:
- found = True
- print("Found " + str(query) + " at position " + str(position))
- position += 1
- if found == False:
- print("The number " + str(query) + " was not found.")
- sequence = [1, 5, 9, 11, 2, 0, 8]
- query = int(input("Which number is required in your linear search? "))
- linearSearch(query, sequence)
- sequence.sort()
- query = int(input("Which number is required in your sorted 'While' linear search? "))
- linearSearchWhile(query, sequence)
Advertisement
Add Comment
Please, Sign In to add comment