Programming 102 Week 4 Tasks (Python)

Continuing on with Programming 102 via FutureLearn, and onto Week 4’s Tasks and Challenges.

4.5 Implementing Linear Search

Task: “Have a go at implementing your own linear search function, in a way that would work on an unsorted sequence of integers.”

# geektechstuff
# Linear Search
sequence = [‘A’,’B’,’C’,’D’]
def sequence_while(list):
position = 0
while position <len(sequence):
    print(sequence[position],”is at position”,str(position))
position += 1
def sequence_loop(list):
for position inrange(len(sequence)):
    print(sequence[position],’ is at position’,str(position))
def sequence_enumerate(list):
for position,item inenumerate(sequence):
    print(item,’is at position’,position)
def while_find(list,item_to_find):
position = 0
while position <len(sequence):
    if sequence[position] == item_to_find:
        print(sequence[position],”is at position”,str(position))
    break
else:
   position += 1

102_4_5_linear_search_geektechstuff
Python Search Functions

One response to “Programming 102 Week 4 Tasks (Python)”

Welcome to GeekTechStuff

my home away from home and where I will be sharing my adventures in the world of technology and all things geek.

The technology subjects have varied over the years from Python code to handle ciphers and Pig Latin, to IoT sensors in Azure and Python handling Bluetooth, to Ansible and Terraform and material around DevOps.

Let’s connect