Accept only vowel strings
EasyString Programs · 93 of 106
Write a Python program to accept a string only if it contains vowels only.
Outputpython not accepted
aaieou accepted
Approach
all(ch in "aeiou" for ch in text).
Solution
Python
for text in ["python", "aaieou"]: print(text, "accepted" if text and all(ch in "aeiou" for ch in text.lower()) else "not accepted")
Output
python not accepted
aaieou accepted
Line by line
Line 2text and ... rejects the empty string, for which all() would return True.
Learn the concept
New to this topic? Read the lesson, then come back.
More string programs
← All 106 String Programs