mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-12 01:00:13 -04:00
1.8 KiB
1.8 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 655774d01daeeaa1978b99d5 | Крок 29 | 20 | step-29 |
--description--
Вважається, що спочатку всі інші вузли в графі розташовані на нескінченній відстані від вихідного вузла, оскільки відстань ще не визначена.
Створіть умову else та призначте нескінченне значення до вузла в словнику distances. Для цього використайте функцію float() з аргументом у вигляді рядка 'inf', щоб створити число з рухомою комою, яке представляє додатну нескінченність.
--hints--
Ви повинні мати умову else.
({ test: () => {
const shortest = __helpers.python.getDef(code, "shortest_path");
const {function_body} = shortest;
assert(function_body.match(/^(\s*)if.*:.*^\1else\s*:/ms));
}
})
Призначте float('inf') до distances[node] в межах нової умови else.
({ test: () => {
const commentless_code = __helpers.python.removeComments(code);
const {block_body} = __helpers.python.getBlock(commentless_code, "else");
assert(block_body.match(/^\s+distances\s*\[\s*node\s*\]\s*=\s*float\s*\(\s*("|')inf\1\s*\)\s*$/));
}
})
--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 = []
distances = {}
for node in graph:
unvisited.append(node)
if node == start:
distances[node] = 0
--fcc-editable-region--