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}')
sentence = input()
words = sentence.split()
reversed_words = [word[::-1] for word in words]
print(" ".join(reversed_words))
sentasce=input("enter your sentasce>>>")
li_sentasce=[]
for t in sentasce:
li_sentasce.append(t)
mirroring=li_sentasce[: :-1]
new_mirrored_sentacse=[]
for i in mirroring:
new_mirrored_sentacse.append(i)
print("".join(new_mirrored_sentacse))
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.