Python Practice › String Programs › Program 93
Accept only vowel strings
Write a Python program to accept a string only if it contains vowels only.
Input
"python", "aaieou"
Output
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")Output
python not accepted aaieou accepted
Line by line
Line 2
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.