Repeat the Front
Sometimes you need to take a short prefix of a string and repeat it several times, for example to build a pattern or a test string. Write a function front_times that takes a string s and a number n. Take the first 3 characters of the string, or the whole string if it is shorter, and repeat that fragment n times.
Примеры
Ввод
"Chocolate", 2Вывод
"ChoCho"Ввод
"Chocolate", 3Вывод
"ChoChoCho"Ввод
"Ab", 4Вывод
"AbAbAbAb"Нужно реализовать
def front_times(s: str, n: int) -> str:
Теги
strings
Prijavite se za ogled zgodovine oddaj
PrijavaPrijavite se za uporabo mentorja UI
PrijavaVisible tests
1
Input
"Chocolate", 2Expected
"ChoCho"2
Input
"Chocolate", 3Expected
"ChoChoCho"3
Input
"Ab", 4Expected
"AbAbAbAb"4
Input
"Ab", 0Expected
""5
Input
"", 5Expected
""6
Input
"Chocolate", -1Expected
""Focus radio
Paused · SomaFM · Fluid