gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
Write a program (using functions!) that asks the user for a long string containing…
- User
Write a program (using functions!) that asks the user for a long string containing multiple words. Print back to the user the same string, except with the words in backwards order
- Assistant
def reverse_string(): string = input("Enter a long string containing multiple words: ") words = string.split() reversed_words = words[::-1] reversed_string = " ".join(reversed_words) print(reversed_string)
reverse_string()