Answer to Question #290234 in Python for pooja

Question #290234

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

1
Expert's answer
2022-01-24T18:38:29-0500
def IsVowel(char):
    return (char.lower() in ['a', 'e', 'i', 'o', 'u'])

def RotateLeft(word):
    return word[1:] + word[0]

def Rotate(word):
    if IsVowel(word[0]):
        return word
    for i in range(1, len(word)):
        word = RotateLeft(word)
        if IsVowel(word[0]):
            return word
    return RotateLeft(word)

result = ''
for ​w in input().split():
    result += Rotate(w) + ' '
result = result[:-1]

print(result)

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