Answer to Question #319176 in Python for suryaakana

Question #319176

swap letters in the string until vowel comes


1
Expert's answer
2022-03-27T17:53:24-0400
# swap characters in string
def swap_characters(string):
    vowels = ['a', 'e', 'i', 'o', 'u']
    for letter in string:
        if letter in vowels:
            break
        else:
            return string[-1:] + string[1:-1] + string[:1] + string[2:3]


# take string from user
str_0 = input("Please enter string: ")
print(swap_characters(str_0))

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