• 1
    Input and Output Data
    • Tasks
  • 2
    Conditions
    • Tasks
  • 3
    For Loop
    • Tasks
  • 4
    Strings
    • Tasks
  • 5
    While Loop
    • Tasks
  • 6
    Lists
    • Tasks
  • 7
    Two-Dimensional Arrays
    • Tasks
  • 8
    Dictionaries
    • Tasks
  • 9
    Sets
    • Tasks
  • 10
    Functions and Recursion
    • Tasks
  • к

Занятие 6. Lists

Difficulty level:

Task«Walk ten minutes»

You live in a city with an ideal grid of roads and use a mobile application for walking. The application generates the route in the form of a list of directions: 'n' (north), 's' (south), 'w' (west), 'e' (east). Each direction means the passage of one quarter in one minute. You need to determine whether the proposed route will return you to the starting point in exactly 10 minutes.

Input format

a line containing the direction of movement through a gap, where each direction is represented by the letter: N, S, W, E

Output format

Tecst "Yes" if the route lasts exactly 10 minutes and returns to the starting point, otherwise "no"

Example

Input

n s n s w e w e n s

Output

true

Hint

There will be no clue here, decide for yourself!

main.py
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Test 10
Developer’s solution
# Читаем строку с направлениями и разделяем по пробелам
directions = input().split()

# Проверяем, что маршрут содержит ровно 10 направлений
if len(directions) != 10:
    print("NO")
else:
    # Считаем количество каждого направления
    north_count = directions.count('n')
    south_count = directions.count('s')
    west_count = directions.count('w')
    east_count = directions.count('e')
    
    # Проверяем, возвращаемся ли мы в исходную точку
    # Север должен компенсироваться югом, запад - востоком
    if north_count == south_count and west_count == east_count:
        print("YES")
    else:
        print("NO")

🎉 Congratulations! 🎉

You did an excellent job with the task! It was a challenging problem, but you found the correct solution. You are one step closer to mastering programming! Keep up the good work, because every stage you pass makes you even stronger.

AD

Advertisement

red-snake blue-snake green-snake

Running your code...

Помощник ИИ

Привет! Я твой помощник по программированию. Задавай любые вопросы по Python, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!