0

new to python. so i have this function, and I don't know how to get it to take two arguments and return it in another list with their positions. in the main program i want it to call x to search for in the list, and print the meassage where it occurs. am i going about this the right way? this what I came up with. would really appreciate the help thanks in advance.

def find_multiple():
    arg1 = input(" L: " )
    arg2 = input(" x: ")

    return L

def main():
    L = [4, 10, 4, 2, 9, 5, 4 ]
    x = int(input("Enter an element to search for in the list: "))
    if (len(L_indexes) == 0):
        print(x, " does not occur in L.")
        L =[]
        results = L    

print("enter an element to search for in the list: " )
if(len(L) == 0):
    print("element does not occur in the list")
else:
    print("the number of occurrences in L: ", x)

main()
Mankarse
  • 39,818
  • 11
  • 97
  • 141
noobie
  • 43
  • 5

1 Answers1

1
def add(a, b):
    return a + b

Edit: Based on what you posted this is what I think you are trying to do.

def search(myBigFancyX, myBigFancyList):

    counter = 0
    for number in myBigFancyList:
        if number == myBigFancyX:
            counter += 1
    return counter

if __name__ == "__main__":

    l = [4, 10, 4, 2, 9, 5, 4 ]
    x = int(input("Enter an element to search for in the list: "))

    occurances = search(x, l)
    if occurances == 0:
        print("element does not occur in the list")
    else:
        print("the number of occurrences in L: ", occurances)
John
  • 13,197
  • 7
  • 51
  • 101
  • ahh yes thank you. i was unsure as to where the arguments went. I had thought as what you posted here at first, but then I had doubts. thanks, this was a big help. – noobie Nov 02 '12 at 02:17
  • `search` appears to be a long way of writing `myBigFancyList.count(myBigFancyX)`... – Jon Clements Nov 02 '12 at 02:18
  • @JonClements yep, but I'm willing to bet his teacher is expecting him to use primitives and what naught. – John Nov 02 '12 at 02:22