Step Through Text

This function helps you practice walking through a string with a fixed step, like choosing every second, third, or fourth character. Write a function every_nth that takes a non-empty string s and a number n. Return a string made from characters at indices 0, n, 2n, 3n, and so on until the index goes past the end of the string.

Примеры

Ввод
"Miracle", 2
Вывод
"Mrce"
Ввод
"abcdefg", 2
Вывод
"aceg"
Ввод
"abcdefg", 3
Вывод
"adg"

Нужно реализовать

def every_nth(s: str, n: int) -> str:

Теги

strings
PostgreSQLv16

Тук ще се появи резултатът от изпълнението на кода

Visible tests
1
Input
"Miracle", 2
Expected"Mrce"
2
Input
"abcdefg", 2
Expected"aceg"
3
Input
"abcdefg", 3
Expected"adg"
4
Input
"abcdefg", 1
Expected"abcdefg"
5
Input
"MIRACLE", 10
Expected"M"
6
Input
"Hello, World!", 2
Expected"Hlo ol!"
Focus radio
Paused · SomaFM · Fluid