can you please fix the print error in this python code: filename = "DistanceData.csv"…
- User
can you please fix the print error in this python code: filename = "DistanceData.csv" 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): f = open(filename, "r") all_data = f.readlines() f.close() dist_dict = {} connectivity_dict = {} line_num = 0 for line in all_data: line = line.replace("\n", "") line = line.split(",") if line_num > 2: source = int(line[1]) dest_idx = 0 for dist in line[2:]: if source == dest_idx: continue if "-" not in dist: 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 dist_dict, connectivity_dict def DijkstrasAlgorithm(start, goal, dist_dict, connectivity_dict): unvisited_nodes = list(connectivity_dict.keys()) dist = {} prev = {} for node in unvisited_nodes: dist[node] = 10000000 dist[start] = 0 while len(unvisited_nodes) > 0: unvisited_nodes = sorted(list(unvisited_nodes), key = lambda x: dist[x]) node = unvisited_nodes[0] for neighbour_node in connectivity_dict[node]: alt = dist[node] + dist_dict[(node, neighbour_node)] if alt < dist[neighbour_node]: dist[neighbour_node] = alt prev[neighbour_node] = node unvisited_nodes.remove(node) return dist, prev if name == "main": 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: print("\nSelect an option.") print("0. Find path to destination.") print("q. Quit the program.") choice = input("Selection:") if choice not in ["0", "q"]: 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": print("Program ending now.") break if choice == "0": 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(f"{i}. {store_name_dict[i]}") choice = input("Selection: ") if int(choice) not in store_name_dict: 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: print("\nPlease enter the corresponding value of the department you wish to go to:") for i in range(len(store_name_dict)): print(f"{i}. {store_name_dict[i]}") choice = input("Selection: ") if int(choice) not in store_name_dict: 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) dist, prev = DijkstrasAlgorithm(start_store, destination_store, dist_dict, connectivity_dict) node = destination_store path = [] while node in prev: path.append(node) 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:") print("\nhello") i = 0 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
- Assistant
- User
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.