Due: May 04, 2018 11 : 59 pm submit Instructions from your teacher: Problem Comp
ID: 3719947 • Letter: D
Question
Due: May 04, 2018 11 : 59 pm
submit
Instructions from your teacher:
Problem
Complete the function reverseStringWords() to take in a string and reverse the order of the words in the string. In other words, you shouldn't reverse the string letter by letter, but word by word.
You may not use Python's built-ins like reversed() or slice the string backwards.
It's ok to use the split() function.
Example
reverseStringWords("Murt likes Jim") # returns "Jim likes Murt"
def reverseStringWords(string):?
1 def reverseStringWords(string): Problem Complete the function reversestringWords() to take in a string and reverse the order of the words in the string. In other words, you shouldn't reverse the string letter by letter, but word by word. You may not use Python's built-ins like reversed() or slice the string backwards It's ok to use the split() function. Example reversestringWords (''Hurt likes Jim") # returns "Jim Ii kes Murt"Explanation / Answer
def reverseStringWords(string): words = string.split() result = '' i = len(words) - 1 while i >= 0: result += words[i] if i != 0: result += ' ' i -= 1 return result
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.