please help I've been trying to implement this linear_search algorithm in python but is not working. when i type in the first element in the array i get a True, but when i type in other elements in the array the output returns False. what is wrong with my code?

def linear_search(A, n, v):
    answer = False
    n = len(A)
    for i in range(n):
            if A[i] == v:
                    answer = i
            else:
                    return None
share|improve this question

put on hold as off-topic by Heslacher, alecxe, Peilonrayz, Mast, BCdotWEB Apr 7 at 14:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – Heslacher, alecxe, Peilonrayz, Mast, BCdotWEB
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information. – Heslacher Apr 7 at 13:47
1  
Try manually going through your code to find the problem, by writing each step down on a piece of paper. You should be able to find the error quickly. – Peilonrayz Apr 7 at 13:54
    
For starters, your indentation is wrong. Indentation is very important in Python. – Mast Apr 7 at 13:56
    
thanks for the criticism am a newbie i need more of it so i can be a guru – krauly williams Apr 7 at 16:38

Browse other questions tagged or ask your own question.