0

蟒蛇新手。所以我有这个函数,我不知道如何让它接受两个参数并将其返回到另一个列表中,并附上它们的位置。在主程序中,我希望它调用 x 在列表中搜索,并打印它出现的位置。我会以正确的方式解决这个问题吗?这就是我想出的。非常感谢您的帮助。

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()
4

1 回答 1

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

编辑:根据您发布的内容,这就是我认为您正在尝试做的事情。

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)
于 2012-11-02T01:50:19.753 回答