Perfect Ten-Minute Walk
Imagine walking around the block, where each step takes one minute and moves you north, south, east, or west. Write is_valid_walk, which checks the list of directions walk. Return True only if the walk lasts exactly 10 minutes and ends at the same point where it started.
Примеры
Ввод
["n", "s", "n", "s", "n", "s", "n", "s", "n", "s"]Вывод
TrueВвод
["w", "e", "w", "e", "w", "e", "w", "e", "w", "e"]Вывод
TrueВвод
["w"]Вывод
FalseНужно реализовать
def is_valid_walk(walk: list[str]) -> bool:
Теги
arraymath
Logga in för att se historik över inskick
Logga inLogga in för att använda AI-mentorn
Logga inVisible tests
1
Input
["n","s","n","s","n","s","n","s","n","s"]Expected
True2
Input
["w","e","w","e","w","e","w","e","w","e"]Expected
True3
Input
["w"]Expected
False4
Input
["n","n","n","s","n","s","n","s","n","s"]Expected
False5
Input
["n","s","e","w","n","s","e","w","n","s"]Expected
True6
Input
["w","e","w","e","w","e","w","e","w","e","w"]Expected
FalseFocus radio
Paused · SomaFM · Fluid