Write a programExercise 1/4Basic10 XP

Words reversed with a stack

Task

The program reads a sentence and prints its words in reverse order, separated by single spaces.

Use a stack: put the words into a list with append, then take them out with pop() until the stack is empty. Do not use reverse, reversed or the slice [::-1].

For the sentence ide to ako po masle the program prints masle po ako to ide.

Examples

  • Input

    ide to ako po masle

    Expected output

    masle po ako to ide

Rules

  • Take the words off the stack with pop().

  • Reverse the order with a stack - no reverse, reversed or [::-1].

After you submit, 3 hidden tests will also check your solution: one word, several spaces between words, numbers.

Python starts the first time you run code.

Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.

Input (stdin)

Each line = one call to input().

Output

Hints

Try it yourself first. Each hint reveals a little more - and lowers the reward a little.

Signed out, hints are free - but no XP is awarded either.

Solution

The solution unlocks after the last hint.