Answer to Question #204520 in Python for Latha

Question #204520

Vowel Sound


Given a sentence, write a program rotate all the words left, so that every word starts with a vowel.

Note: If there is no vowel in the word, do not rotate it.

Sample Input

I saw a DRAGON flying in the sky

Sample Output

I aws a AGONDR ingfly in eth sky


def vowels_rotate(arg):

    vowels =['a', 'e', 'i', 'o', 'u']

    for indx, letter in enumerate(arg):

        if letter.lower() in vowels:

            return arg[indx:]+arg[:indx]

    return arg 

user_str = input("Enter your string: ")

words = user_str.split()

for i in range(len(words)):

    words[i] = vowels_rotate(words[i])

print(*words,sep="  ")


In the above code using enumerate to get the expected output. But, should we write without using enumerate ?


1
Expert's answer
2021-06-08T23:47:41-0400
def rotate_vowel(word):
    vowels_letters =['a', 'e', 'i', 'o', 'u']
    for row, col in enumerate(word):
        if col.lower() in vowels_letters:
            return word[row:]+word[:row]
    return word


# user inputting a sentence
sentence = input("Enter your sentence: ")
words_in_sentence = sentence.split()
#Iterating over the words in the sentence
for x in range(len(words_in_sentence )):
    words_in_sentence[x] = rotate_vowel( words_in_sentence[x])
print(*words_in_sentence,sep="  ")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS