功能
def find_value(num_list,target):
target_loc = [] # list to store the location of the target
condition = True
while condition == True:
for target in num_list:
if target in num_list:
index = num_list.index(target)
target_loc.append(index)
condition = True
else:
condition = False
return target_loc
主程序:
num_list = keep_positive_numbers()
print()
print("List entered: ",num_list)
print()
target = int(input("Enter target = "))
print()
list = find_value(num_list,target)
print("Target exists at location(s): ",list)
输出
输入一个正整数:9 输入一个正整数:9 输入一个正整数:8 输入一个正整数:0
输入的列表:[9,9,8]
输入目标= 7
目标存在于[0、0、2]个位置