Implement the Shortest Path Algorithm - Step 12

Tell us what’s happening:

My code should be OK, but I get this error message:
// running tests
2. Your if statement should check if the node is unvisited (visited[node_no] is falsy) and distances[node_no] is less than min_distance.
// tests completed

Your code so far

INF = float('inf')
adj_matrix = [
    [0, 5, 3, INF, 11, INF],
    [5, 0, 1, INF, INF, 2],
    [3, 1, 0, 1, 5, INF],
    [INF, INF, 1, 0, 9, 3],
    [11, INF, 5, 9, 0, INF],
    [INF, 2, INF, 3, INF, 0],
]

def shortest_path(matrix, start_node, target_node=None):
    n = len(matrix)
    distances = [INF] * n
    distances[start_node] = 0
    paths = [[node_no] for node_no in range(n)]
    visited = [False] * n


# User Editable Region

    for _ in range(n):  
        min_distance = INF  
        current = -1  
        for node_no in range(n):  
            if visited[node_no] is False and distnaces[node_no] < min_distance:
                pass


# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0

Challenge Information:

Implement the Shortest Path Algorithm - Step 12

this is not checking if something is falsy, you may want to review what is the behaviour of a falsy value

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.