mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-12 01:00:13 -04:00
1.6 KiB
1.6 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 65578cee7f2cb8b80127cce2 | Крок 39 | 20 | step-39 |
--description--
Перед викликом print створіть цикл while, який виконується, поки unvisited не порожній. Використайте ключове слово pass, щоб заповнити тіло циклу.
--hints--
Ви повинні мати цикл while, який виконується, поки unvisited не порожній. Не забудьте ключове слово pass.
({ test: () => {
const commentless_code = __helpers.python.removeComments(code);
const {function_body} = __helpers.python.getDef(commentless_code, "shortest_path");
assert(function_body.match(/^\s+while\s+(unvisited|unvisited\s*!=\s*\[\s*\]|len\s*\(\s*unvisited\s*\)\s*(>|!=)\s*0)\s*:/m));
const {block_body} = __helpers.python.getBlock(commentless_code, /while\s+(unvisited|unvisited\s*!=\s*\[\s*\]|len\s*\(\s*unvisited\s*\)\s*(>|!=)\s*0)\s*/);
assert(block_body.match(/\s+pass/))
}
})
--seed--
--seed-contents--
my_graph = {
'A': [('B', 3), ('D', 1)],
'B': [('A', 3), ('C', 4)],
'C': [('B', 4), ('D', 7)],
'D': [('A', 1), ('C', 7)]
}
--fcc-editable-region--
def shortest_path(graph, start):
unvisited = list(graph)
distances = {node: 0 if node == start else float('inf') for node in graph}
paths = {node: [] for node in graph}
paths[start].append(start)
print(f'Unvisited: {unvisited}\nDistances: {distances}\nPaths: {paths}')
#shortest_path(my_graph, 'A')
--fcc-editable-region--