Reversing the words of the sentence
Write a program that receives a sentence and reverses each word and re -print the sentence without changing the order of words.
Input: Hello Amir ...
Olleh RIMA ...
Write a program that receives a sentence and reverses each word and re -print the sentence without changing the order of words.
Input: Hello Amir ...
Olleh RIMA ...
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
r = input("matn: ") print(r[::-1]) # Reverse the string
a=[] b=(input('str:')) for i in b: a.append(i) for j in reversed(a): print(j,end="")
def reverse_words_in_sentence(sentence): words = sentence.split() reversed_words = [word[::-1] for word in words] return ' '.join(reversed_words) sentence = input("Enter a sentence: ") print(reverse_words_in_sentence(sentence))
def reverse_words(sentence): """این تابع کلمات یک جمله را برعکس میکند.""" # Divide the sentence into words words = sentence.split() # Reversing any word reversed_words = [word[::-1] for word in words] # Converting the list of inverse words into a sentence reversed_sentence = ' '.join(reversed_words) return reversed_sentence def main(): # Receive a sentence from the user sentence = input("لطفاً یک جمله وارد کنید: ") # Reversing the words and printing the result result = reverse_words(sentence) print(result) # Implementation of the program main()
en_string = input ('str: ') rev = [i[::-1] for i in en_string.split()] rev_u = " ".join(rev) print (f'{rev_u} --> {en_string}')
def reverse_words(sentence): # Separate sentence words words = sentence.split() # Reversing any word and saving in the new list reversed_words = [word[::-1] for word in words] # Combining the inverse words into a sentence reversed_sentence = " ".join(reversed_words) return reversed_sentence
def str(name): s=name.split() r=map(lambda t:t[::-1],s) return ''.join(r) text=input("text: ") print(str(text))
Submitting answers is currently unavailable.
You must be logged in to access this section.
Login/Sign up If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.