Функция
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]