Python program to accept the strings which contain all vowels
In this tutorial, you will learn to write a program that accepts a string and contains all vowels. Strings in Python are a sequence of characters wrapped inside single, double, or triple quotes. For a given string we have to check if every vowel is present in the string or not. Vowels in either uppercase ( 'A', 'E', 'I', 'O', 'U') or lowercase ('a', 'e', 'i', 'o', 'u') should be considered. For example,
Input: "Python is a Language"
Output: not accepted
To solve this problem, we will create a set of vowels using
set() method. Since both uppercase and lowercase vowels have to be considered, we will convert the string to lower case. Then we will iterate over the string and if any character is a vowel, we will delete it from the vowel set using
In the end, we will check the length of the vowel set. If the length is 0 then the string will be accepted else the string will not be accepted.
set() function will convert any of the iterable to the sequence of iterable elements with distinct elements, commonly called Set.
Follow the algorithm to understand the approach better.
Step 1- Define a function that will check for vowels in a string
Step 2- Convert the string to lower case
Step 3- Create a set of vowels
Step 4- Iterate over the characters in the string
Step 5- Check if the character is in the vowel set
Step 6- If the character is a vowel remove it from the set
Step 7- At last check if the vowel set is empty
Step 8- Print accepted if there is no vowel left in the vowel set
Step 9- Else print not accepted
Look at the program to understand the implementation of the above-mentioned approach. To remove vowel from the set, we have used remove() which is a string class method.
# check if the string
# contains all vowels
s = s.lower()
vowels = set("aeiou")
for char in s:
if char in vowels:
if len(vowels) == 0:
In this tutorial, we have discussed how to check if a string has all the vowels present. We have also seen how to use some built-in functions like set(), lower() and remove() in our program.