Write definition of a function in python that accept a string as a parameter and display those words from the string that starts with capital vowel.
Answers
The following codes have been written using Python.
def cap_vowel(s):
if len(s.split()) == 1:
if s[0] in "AEIOU":
print(s)
else:
print("It does not contain a capital vowel.")
else:
nl = s.split()
vl = list()
for i in nl:
if i[0] in "AEIOU":
vl.append(i)
if len(vl) > 0:
for i in vl:
print(i)
else:
print("No word starts with a capital vowel.")
The function is used to create user-defined functions, such as the one instructed in this question. Once the parameter is given, we check if it's a string having more than one word to proceed accordingly. If it's only a single word, a checking for capital vowels starts using conditional statements. If it has more than a word, lists are created to append the words starting with capital vowels. Appropriate conditional statements and print statements are passed.