Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE HELP ME FIX THIS CODE. IT DOES NOT SHOW THE LOCATION. Finds the locations

ID: 3702627 • Letter: P

Question

PLEASE HELP ME FIX THIS CODE. IT DOES NOT SHOW THE LOCATION.

Finds the locations of a target value in a list Use: locations = find_value(num_list, target)

def find_value(num_list, target):
  
locations = []
size = len(num_list)
for index in range(size):
if target == num_list[index]:
locations.append(index)

return locations

num_list = get_string()
print()
print("{}".format(num_list))
target = int(input("Enter the desired target value: "))

locations = find_value(num_list, target)

print()
print("The locations of the target value are: {}".format(locations))

Explanation / Answer

The problem is solved

def find_value(num_list, target): #convert each element in num_list to an integer using list comprehension
locations = []
num_list=[int(i) for i in num_list]
size = len(num_list)
for index in range(size):
if target == num_list[index]:
locations.append(index)
return locations

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote