In as much detail as possible, add comments to this code and highlight the comments made:
filename = “DistanceData.csv”
# A ditionary that stores the names of all the stores against their unique numbers
store_name_dict = {
0 : “Entrance”,
1 : “Florist”,
2 : “Fresh Produce”,
3 : “Bakery”,
4 : “Toiletries”,
5 : “Frozen”,
6 : “Fresh Meat and Seafood”,
7 : “Dairy Products”,
8 : “Beverages”,
9 : “Clothing”,
10 : “Tech”,
11 : “Pharmacy”,

}



def ReadData(filename):
‘’‘
This function reads data from a file and stores it in a dictionary.
The function stores distances among connected stores. And also stores the neighbors of each store.
‘’’
# Read file data
f = open(filename, “r”)
all_data = f.readlines()
f.close()

dist_dict = {}
connectivity_dict = {}

line_num = 0
for line in all_data:
# Go over line by line
line = line.replace(“\n”, “”)
line = line.split(“,”)

if line_num > 2:
# Skip first two lines then read data and distances and store them in a dictionary.
source = int(line[1])
dest_idx = 0
for dist in line[2:]:
if source == dest_idx:
continue


if “-” not in dist:
# Only add edges to the graph if the nodes are connected to one another.
dist = int(dist.replace(“m”, “”))
dist_dict[(dest_idx, source)] = dist
dist_dict[(source, dest_idx)] = dist

if source not in connectivity_dict:
connectivity_dict[source] = []
if dest_idx not in connectivity_dict:
connectivity_dict[dest_idx] = []

connectivity_dict[source].append(dest_idx)
connectivity_dict[dest_idx].append(source)

dest_idx += 1

line_num += 1
# Return the connected nodes and the distances between them.
return dist_dict, connectivity_dict


def DijkstrasAlgorithm(start, goal, dist_dict, connectivity_dict):
‘’‘
Implementation of dijkstra algorithm. Given goal and start position find the optimal path.
‘’’
# List all nodes that have not been visited. In the beginning these will be all the nodes.
unvisited_nodes = list(connectivity_dict.keys())
dist = {}
prev = {}

# initialize the distances for all the nodes to a very high number
for node in unvisited_nodes:
dist[node] = 10000000

# Set the distance of the current node to 0
dist[start] = 0

# Iterate until all the nodes have been explored
while len(unvisited_nodes) > 0:
# Get the node with the lowest distance to the current node
unvisited_nodes = sorted(list(unvisited_nodes), key = lambda x: dist[x])
node = unvisited_nodes[0]

# Explore neighbors of that node and store their distances in a dictionary.
for neighbour_node in connectivity_dict[node]:
alt = dist[node] + dist_dict[(node, neighbour_node)] # Find distance from current node to neighbor node, if distance is low then update the dictionaries
if alt < dist[neighbour_node]:
dist[neighbour_node] = alt
prev[neighbour_node] = node

unvisited_nodes.remove(node) # Remove the node that has been visited

return dist, prev # Return the distances to each node and also return the trace back dictionary.


def UserFeedback():
‘’‘
This is where the user will be asked to provide feeback
‘’’

while True:
choice = input(“Did you use our navigation system today whilst shopping? (y/n)”).lower()

if choice not in [‘y’, ‘n’]:
print(“Invlid response. Try again.”)
continue

if choice == ‘n’:
return

if choice == ‘y’:
break

valid_choices = [str(i) for i in range(1, 11)]
while True:
choice = input(“i. On a scale from 1- 10, how helpful did you find this navigation aid? (1- not helpful at all, 10 amazingly helpful) “)
if choice in valid_choices:
break
else:
print(“Invlide input, please enter the correct input.”)

while True:
choice = input(“ii. On a scale from 1- 10, how easy did you find using this application? (1- extremely difficult, 10 very easy) “)
if choice in valid_choices:
break
else:
print(“Invlide input, please enter the correct input.”)

while True:
choice = input(“iii. Finally, on a scale from 1- 10 how likely would you be to recommend this navigation aid to others? (1- not at all, 10- extremely likely) “)
if choice in valid_choices:
break
else:
print(“Invlide input, please enter the correct input.”)


if name == “main”:
# This is the main part of the code. The user input is handled here.
# First the data is read from the file
dist_dict, connectivity_dict = ReadData(filename)
print(“Welcome! Today I will to the best of my ability help you navigate your way around the supermarket. Let me know where you are and where you wish to go and I will tell you the shortest path you would be required to take. I hope I’m able to ease your shopping experience today :) “)
while True:
########################################## First user input region start ##########################################
# Ask user for initial input.
print(”\nSelect an option.”)
print(“0. Find path to destination.”)
print(“q. Quit the program (You will be asked to provide feeback regarding our navigation system).”)
choice = input(“Selection:”)

if choice not in [“0”, “q”]: # Check if input is valid
print(“Invalid input chosen. Please select the correct value. These values are either 0 (to find the shortest path) or q (to terminate the programme”)
continue

if choice == “q”: # Quit is user wants to quit
UserFeedback()
print(“Program ending now.”)
print(‘’‘
Thank you for using this navigation aid! We highly value your feedback as we continuously strive to improve.
Please do not hesitate to share your insights and suggestions with us by emailing our regularly checked
inbox at <PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>.
‘’’)
break

if choice == “0”:
########################################## Second user input region start ##########################################
while True:
print(”\nPlease enter the corresponding value of the department you are currently situated at:”)
for i in range(len(store_name_dict)): # Print the names of the stores.
print(f”{i}. {store_name_dict[i]}”)

choice = input(“Selection: “)

if int(choice) not in store_name_dict: # Check validity of input
print(“Invalid input. Please try again and select the correct value that corresponds to the department you are currently in.”)
continue

start_store = int(choice)

while True:
########################################## Third user input region start ##########################################
print(”\nPlease enter the corresponding value of the department you wish to go to:”)
for i in range(len(store_name_dict)): # Print the names of the stores
print(f”{i}. {store_name_dict[i]}”)

choice = input(“Selection: “)

if int(choice) not in store_name_dict: # Check input validity
print(“Invalid input. Please try again and select the correct value that corresponds to the department you would like to go to0.”)
continue

destination_store = int(choice)
# given the starting and goal store, go over the graph and find the best distance.
dist, prev = DijkstrasAlgorithm(start_store, destination_store, dist_dict, connectivity_dict)


# Sort the path for printing
node = destination_store
path = []
while node in prev:
path.append(node) # Add nodes to a list so that it is easier to print
node = prev[node]

path.append(start_store)
path.reverse()


print(f”\nThe path from {store_name_dict[start_store]} to {store_name_dict[destination_store]} is as follows (the final number next to the destination department you have chosen is the total distance in metres it would take you to get to your destination0):”)

i = 0 # Print the stores and their distances.
for path_point in path:
if path_point == start_store:
dist_from_start = 0
else:
dist_from_start = dist[path_point]

print(store_name_dict[path_point], “-”, dist_from_start)

break
break