0

sup i'm pretty bad at this but i'm trying to learn python but i don't really understand why this isn't working. all i want to do is run an unordered sequential search but nothing happens when i run this.

def sequentialSearch(alist, item):
    pos = 0
    found = False

    while pos < len(alist) and not found:
        if alist[pos] == item:
            found = True
        else:
            pos = pos+1

    return found

def main():
    alist = random.sample(range(0, 1000000), 10000)
    sequentialSearch(alist[0:1000], 9)

main()

manually typing this in the python shell works though

>>> alist = random.sample(range(0, 1000000), 10000)
>>> sequentialSearch(alist[0:1000], 9)
False

i know i'm missing something small and dumb but i can't seem to fix it lol

2
  • Welcome! You should call print() to output result to console. Commented Apr 12, 2020 at 23:15
  • Your code does not print anything. But the interactive shell has the feature to print the result of the last entered commanf if it is not None. Commented Apr 12, 2020 at 23:15

1 Answer 1

1

You have to print this or return it, or whatever you would like to do.

print(sequentialSearch(alist[0:1000], 9))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.