我想搜索一个数组并从另一个数组返回一个值。这就是我现在所拥有的。不知道如何让它发挥作用。
CustNumber=str(raw_input("Please enter the Customer's Number:"))
If CustNumber in Customers:
print ("Customer Number: " +str(Customers[i])+"Name:"+(str(Names[i])))
else:
print ("not found")

答案 0 :(得分:0)
此处未定义您的变量i
。您必须首先使用您要查找的元素的索引来定义它。
if CustNumber in Customers:
i = Customers.index(CustNumber)
print ("Customer Number: " +str(Customers[i])+"Name:"+(str(Names[i])))
else:
print ("not found")
您还可以使用错误处理来避免使用if语句:
try:
i = Customers.index(CustNumber)
print ("Customer Number: " +str(Customers[i])+"Name:"+(str(Names[i])))
except ValueError:
print ("not found")