Exercise 2: Reverse a String, Three Ways — Possible Solution ==================================================================== word = "programming" # Version 1 — for ch in word: reversed_word_1 = "" for ch in word: reversed_word_1 = ch + reversed_word_1 print(reversed_word_1) # Version 2 — for i in range(len(word)): reversed_word_2 = "" for i in range(len(word)): reversed_word_2 = word[i] + reversed_word_2 print(reversed_word_2) # Version 3 — for i, ch in enumerate(word): reversed_word_3 = "" for i, ch in enumerate(word): reversed_word_3 = ch + reversed_word_3 print(reversed_word_3) Output: gnimmargorp gnimmargorp gnimmargorp WHY THIS WORKS AS AN ANSWER ------------------------------ All three versions rely on the same trick: instead of appending each new character to the *end* of the result (which would just copy the string back out in its original order), each one is glued onto the *front* — ch + reversed_word instead of reversed_word + ch. Since the loop still visits the original word from first character to last, prepending each one means the very first character processed ("p") ends up at the very end of the result, and the very last character processed ("g") ends up at the front. The three versions only differ in how ch is obtained: directly from the loop (Version 1), looked up by index (Version 2), or unpacked from an enumerate() tuple where the index itself is never actually used (Version 3) — a small hint that Version 3 is over-engineered for this particular problem, since nothing here needed the index at all. Version 1 is the most natural fit.