Skip to content
Related Articles

Related Articles

Improve Article

Python | Program to accept the strings which contains all vowels

  • Difficulty Level : Basic
  • Last Updated : 25 Aug, 2021

Given a string, the task is to check if every vowel is present or not. We consider a vowel to be present if it is present in upper case or lower case. i.e. ‘a’, ‘e’, ‘i’.’o’, ‘u’ or ‘A’, ‘E’, ‘I’, ‘O’, ‘U’ . 
Examples : 

Input : geeksforgeeks
Output : Not Accepted
All vowels except 'o' are not present

Input : ABeeIghiObhkUul
Output : Accepted
All vowels are present

Approach : Firstly, create set of vowels using set() function. Check for each character of the string is vowel or not, if vowel then add into the set s. After coming out of the loop, check length of the set s, if length of set s is equal to the length of the vowels set then string is accepted otherwise not. 
Below is the implementation : 


# Python program to accept the strings
# which contains all the vowels
# Function for check if string
# is accepted or not
def check(string) :
    string = string.lower()
    # set() function convert "aeiou"
    # string into set of characters
    # i.e.vowels = {'a', 'e', 'i', 'o', 'u'}
    vowels = set("aeiou")
    # set() function convert empty
    # dictionary into empty set
    s = set({})
    # looping through each
    # character of the string
    for char in string :
        # Check for the character is present inside
        # the vowels set or not. If present, then
        # add into the set s by using add method
        if char in vowels :
    # check the length of set s equal to length
    # of vowels set or not. If equal, string is 
    # accepted otherwise not
    if len(s) == len(vowels) :
    else :
        print("Not Accepted")
# Driver code
if __name__ == "__main__" :
    string = "SEEquoiaL"
    # calling function

Alternate Implementation :


def check(string):
    string = string.replace(' ', '')
    string = string.lower()
    vowel = [string.count('a'), string.count('e'), string.count(
        'i'), string.count('o'), string.count('u')]
    # If 0 is present int vowel count array
    if vowel.count(0) > 0:
        return('not accepted')
# Driver code
if __name__ == "__main__":
    string = "SEEquoiaL"


Alternate Implementation 2.0 : 


# Python program for the above approach
def check(string):
    if len(set(string.lower()).intersection("aeiou")) >= 5:
        return ('accepted')
        return ("not accepted")
# Driver code
if __name__ == "__main__":
    string = "geeksforgeeks"
not accepted

Alternate Implementation 3.0 (Using Regular Expressions):

  1. Compile a regular expression using compile() for “character is not a, e, i, o and u”.
  2. Use re.findall() to fetch the strings satisfying the above regular expression.
  3. Print output based on the result.


#import library
import re
sampleInput = "aeioAEiuioea"
# regular expression to find the strings
# which have characters other than a,e,i,o and u
c = re.compile('[^aeiouAEIOU]')
# use findall() to get the list of strings
# that have characters other than a,e,i,o and u.
    print("Not Accepted") # if length of list > 0 then it is not accepted
    print("Accepted") # if length of list = 0 then it is accepted

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :