I'm new to programming and learning Python over the web and I'm stuck on this problem.
The objective is to have a list of numbers and create a function that will evaluate that list of numbers and print out the matches and the position in the list the matches are found at.
I think I'm 90% there, but the function I wrote only prints out the first match it finds, then ends.
Here's what I have so far:
list=[36, 36, 79, 96, 36, 91, 77, 33, 19, 3, 34, 70, 12, 12, 54, 98, 86, 11, 17, 17] def find(list,x): for i in range(len(list)): if x == i: print ("Found",x,"at position",i) find(list,12) find(list,91) find(list,80)
This correctly prints out:
"Found 12 at position 12", but fails to print the complete answer which is:
Found 12 at position 12 Found 12 at position 13 Found 91 at position 5
It appears the loop is ending prematurely, but I don't understand why. I realize this is probably pretty basic stuff, but I appreciate your time and any advice. Thanks in advance.