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
Kirjaudu sisään nähdäksesi palautushistorian
Kirjaudu sisäänKirjaudu sisään käyttääksesi tekoälymentoria
Kirjaudu sisäänVisible tests
1
Input
"Miracle", 2Expected
"Mrce"2
Input
"abcdefg", 2Expected
"aceg"3
Input
"abcdefg", 3Expected
"adg"4
Input
"abcdefg", 1Expected
"abcdefg"5
Input
"MIRACLE", 10Expected
"M"6
Input
"Hello, World!", 2Expected
"Hlo ol!"Focus radio
Paused · SomaFM · Fluid