python新手。所以我有这个功能,我不知道如何让它采取两个参数并将其返回到另一个列表中的位置。 在主程序中,我希望它在列表中调用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()
答案 0 :(得分: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)