← Back to challenges

Breaking News!

PythonHardstringsloops

Instructions

A local news station needs your help to generate the scrolling text for the headlines!

Create a function that returns a list of strings, where each string contains a single frame of what the scrolling text will look like.

  • Text will scroll from right to left.
  • The screen will have a width of n characters.
  • Start and stop when no letters appear on the screen.

The example below will demonstrate the output when the screen width is 10.

Examples

news_at_ten("innokodakademija", 10) ➞ [
  "          ",
  "         e",
  "        ed",
  "       eda",
  "      edab",
  "     edabi",
  "    innokodakademija",
  "   innokodakademija ",
  "  innokodakademija  ",
  " innokodakademija   ",
  "innokodakademija    ",
  "dabit     ",
  "abit      ",
  "bit       ",
  "it        ",
  "t         ",
  "          "
]

Notes

  • Every string should be n characters long, so you should pad the string with spaces if the text isn't long enough.
  • Similarly, if the text is too long for the screen width, then it's only possible to display a fraction of the text at a time.
  • See the Tests tab for more examples.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.