CodeSolved

A comprehensive source of programming questions and exercises

Reversing the words of the sentence

Practice Easy 193/ Download 1138 Views

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 ...

12 Answers

This answer is only visible to premium members
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

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
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

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
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

This answer is only visible to premium members

Subscription is currently unavailable.
r = input("matn: ")
h = ""
for i in r: # Reverse the string
    h = i + h
print(h)
Hossien Download Python
a=[]
b=(input('str:'))
for i in b:
    a.append(i)
for j in reversed(a):
      print(j,end="")
Maryam.n Download Python
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()
Mma123 Download Python
en_string = input ('str: ')
rev = [i[::-1] for i in en_string.split()]
rev_u = " ".join(rev)
print (f'{rev_u} --> {en_string}')
User 918 Download Python
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
Milad.bio Download Python
def str(name):
    s=name.split()
    r=map(lambda t:t[::-1],s)
    return ''.join(r)
text=input("text: ")
print(str(text))
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

Related content

Detection using AI
×
×
Close