CJCoding With Joseph
15free / daySign inCreate account

Reverse A Word With A Stack

The Stack class is given. Write reverse_word(text: str) -> str that pushes every character of text onto a stack, then pops until the stack is empty, adding each popped character to a result string, so the word comes back reversed; a stack is last in, first out. Use the stack's push(), pop() and is_empty() methods. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line, the word; the tests print the string your function returns.

Expected Output:

kcats

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
Data Structures & Algorithms
📥 Auto-Input:
stack\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.