How can I ensure the Capital letters are in the right place?"** Explanation 1) Below is program that define function which accepts a text string and returns a new string constructed by finding all its vowels and reversing their order while keeping all other characters in same order It defines a function reverse_vowels returns new string with vowels reversed Create a list to store vowels in text Loop through all characters in text append the vowels in list Create a new text string to store vowels in reverse Loop through all characters in text if character is vowel pop one vowels from end and update new_text else keep the other text same return new text It has a test code which calls function reverse_vowels with multiple inputs and display new returned text 2) Save program in python file and run Program """Program that define function which accepts a text string and returns a new string constructed by finding all its vowels and reversing their order while keeping all other characters in same order""" #function returns new string with vowels reversed def reverse_vowels(text): #Create a list to store vowels in text vowels = [] #Loop through all characters in text for ch in text: if ch in "aeiouAEIOU": #append the vowels in list vowels.append(ch) #Create a new text string to store vowels in reverse new_text = "" #Loop through all characters in text for ch in text: if ch in "aeiouAEIOU": #pop one vowels from end and update new_text new_text += vowels[-1] vowels = vowels[:-1] else: #keep the other text same new_text += ch #return new text return new_text #Test Code #Call function reverse_vowels with multiple inputs and display new returned text print(reverse_vowels("Revorse the vewels")) print(reverse_vowels("Bengt Hilgursson")) print(reverse_vowels("Why do you laugh? I chose the death")) print(reverse_vowels("These are people you protect with your pain!")) print(reverse_vowels("Who's the leader of the club that's made for you and me? \ T-R-C-K-Y M-O-U-S-E! Tricky Mouse! TRICKY MOUSE! Tricky Mouse! TRICKY MOUSE!\ Forever let us hold our Hammers high! High! High! High!"))
1) Below is program that define function which accepts a text string and returns a new string constructed by finding all its vowels and reversing their order while keeping all other characters in same order
- It defines a function reverse_vowels returns new string with vowels reversed
- Create a list to store vowels in text
- Loop through all characters in text
- append the vowels in list
- Create a new text string to store vowels in reverse
- Loop through all characters in text
- if character is vowel pop one vowels from end and update new_text
- else keep the other text same
- return new text
- It has a test code which calls function reverse_vowels with multiple inputs and display new returned text
2) Save program in python file and run
"""Program that define function which accepts a text string and returns a new string
constructed by finding all its vowels and reversing their order while keeping all
other characters in same order"""
#function returns new string with vowels reversed
def reverse_vowels(text):
#Create a list to store vowels in text
vowels = []
#Loop through all characters in text
for ch in text:
if ch in "aeiouAEIOU":
#append the vowels in list
vowels.append(ch)
#Create a new text string to store vowels in reverse
new_text = ""
#Loop through all characters in text
for ch in text:
if ch in "aeiouAEIOU":
#pop one vowels from end and update new_text
new_text += vowels[-1]
vowels = vowels[:-1]
else:
#keep the other text same
new_text += ch
#return new text
return new_text
#Test Code
#Call function reverse_vowels with multiple inputs and display new returned text
print(reverse_vowels("Revorse the vewels"))
print(reverse_vowels("Bengt Hilgursson"))
print(reverse_vowels("Why do you laugh? I chose the death"))
print(reverse_vowels("These are people you protect with your pain!"))
print(reverse_vowels("Who's the leader of the club that's made for you and me? \
T-R-C-K-Y M-O-U-S-E! Tricky Mouse! TRICKY MOUSE! Tricky Mouse! TRICKY MOUSE!\
Forever let us hold our Hammers high! High! High! High!"))
![Revorse the vewels
def reverse vowele(text):
Given a text string, create and return a new string constructed by finding all its vowels (in this
problem, 'aeiouAEIOU') and reversing their order, while keeping all other characters exactly as
they were in their original positions. Furthermore, the capitalization of each position must remain
the same as it was in the original text. For example, reversing the vowels of 'Ilkka' should
produce 'Alkki' instead of 'alkkI'. Results of applying this operation to perfectly ordinary
English sentences often comically resemble pig latin imitations of other languages.
Along with many possible ways to perform this dance, one straightforward way to reverse the
vowels starts by appending the vowels of text into a separate list, and initializing the result to
an empty string. Then, loop through all characters of the original text. Whenever the current
character is a vowel, pop one from the end of the list of the vowels. Convert that vowel to either
upper- or lowercase depending on the case of the vowel that was originally in that position, and add
it to result. Otherwise, add the character from the original text to the result as it was.
text
Expected result
'Revorse the vewels
'Reverse the vowels'
'Bengt Hilgursson'
'Bongt Hulgirssen'
'Why do you laugh? I chose the 'Why da yee leogh? I chusa thu
death."
dooth.'
"Thisa uro thi peoplu yoe
protect weth year peenl'
"These are the people you
protect with your painl'
"who's the leader of the club
that's made for you and me? T- thot's mude fer yeo end mu? T-
R-1-C-К-х М-0-0-5-EI Tricky
Mousel TRICKY MOUSEI Tricky
Mousel TRICKY MOUSEI Forever
let us hold our Hammers highi
Highl Highl Highl"
"Whi's thi liider af thu clob
R-0-с-к-х м-1-E-S-01 Trocky
Miesul TROCKY MIESUI Trocky
Miesul TROCKY MIESAI Furovor
let as hald uer Hommers haghi
Heghi Heghi Hoghl"](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F886e41a3-9447-40ef-9864-5f77f8e5f654%2F5bacc106-f571-4148-bbc7-f482e261555d%2F1yr2fy7_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)