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