Python Practice › String Programs › Program 93

Accept only vowel strings

EasyString Programs · 93 of 106

Write a Python program to accept a string only if it contains vowels only.

Advertisement
Input
"python", "aaieou"
Output
python not accepted
aaieou accepted

Approach

  1. 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 2

text and ... rejects the empty string, for which all() would return True.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More string programs

← All 106 String Programs