Building Travel & Flight Optimization App - Graded assignment failing even though the code passed all the unit test cases

I’m stuck on Exercise 2 (optimize_world_tour) because I’m seeing conflicting validator expectations.

In unittests.py, the validator is:

def is_valid_tour(graph_json, tour, start_node):
    if tour[0] != start_node: ...
    tour_nodes = set(tour)
    if tour_nodes != set(graph_json['nodes']): ...
    if len(tour) != len(tour_nodes):
        return False, "Tour has duplicate nodes"
    return True, ""

So this implies the tour must:

  • start with start_node

  • include all nodes exactly once

  • no duplicates → meaning it should be an open tour of length N (NOT [... , start])

Also, calculate_tour_distance already closes the loop using modulo:

to_node = tour[(i + 1) % len(tour)]

My function returns for 8 nodes:
[0, 1, 7, 6, 5, 4, 3, 2]

  • starts ok :white_check_mark:

  • length ok :white_check_mark:

  • duplicates? False :white_check_mark:

But when I run the assignment test/grade cell I get:
“Invalid tour (5/8/10/12/15 countries). Tour must end with 0 (closed tour), got X.”

I searched the workspace and the string “must end with 0” doesn’t appear in unittests.py (only appears in the notebook itself). So it looks like there’s another checker being used that requires the tour to end with start, which would introduce a duplicate and fail is_valid_tour.

Question:
Which tour format is correct for submission?

  1. Open tour: [start, ..., last] (unique nodes)
    or

  2. Closed tour: [start, ..., last, start]

And which test function/cell is the actual autograder using?

Any guidance from mentors/instructors would be hugely appreciated—right now the checks appear inconsistent.

Thanks!

This is not requested, only a list of tour nodes is the output!

This is correct!

Also part of this course is to work together with the LLM to provide you further clarification, exactly about these questions actually! Of course one you feed the skeleton code and the requirements of the exercise!