Logic Building
# Take string
s = input("Enter string: ")
# Reverse words
words = s.split()
reversed_words = words[::-1]
result = ' '.join(reversed_words)
print(f"Reversed: {result}")Output
Enter string: Hello World Programming Reversed: Programming World Hello
Split, reverse list, join.
Key Concepts:
- Split into words
- Reverse word list
- Join with spaces