Reverse words

Language: Python

Task:

To complete the function that accepts a string parameter, and reverses each word in the string. All spaces in the string should be retained.

Parameters:

def reverse_words(text):

     """This function reverses each other words in a sentence but keeps the words in the same place"""

#Split the sentence into a list so that the words can be worked at separately rather than reversing the whole list
text=text.split(" ")  
    #Go through each of the words reversing them and turning them into lists
for i in range (0,len(text)):
    text[i]=reversed(text[i])
    #Join the lists together to make a list of reversed words
for i in range (0,len(text)):
    text[i]="".join(text[i])
#Join the whole list together to make a reversed sentence
text= " ".join(text)
return text

text = input ("Please give me a sentence.")
 print (reverse_words(text))