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 ?
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=" ")
Comments
Leave a comment