Javatpoint Logo
Javatpoint Logo

Python Program for accepting the strings which contains all vowels

In this tutorial, we will discuss how a Python program can accept only the string which contains every vowel.

In the following example, we pass a string to check whether all the vowels are present or not. We have considered that both upper case and lowercase vowels are acceptable. That is "A", "E", "I", "O", "U" or "a", "e", "i", "o", "u".

Example:

Solution Approach

At first, we will create a set of vowels by using the set() function. Then we will check whether each character of the string is a vowel or not. If the character is a vowel, we will add it into the set "string_1". After coming out of the loop, we will check the length of the set "string_1". The string will only be accepted if the length "string_1" set is equal to the length of the "vowel_1" string; otherwise, it will not accept the string.

Method 1:

Output:

#1
Enter the String of characters:  aideiofguhs
The string is Accepted
#2
Enter the String of characters:  aideiofghs
The string is Not Accepted

Explanation:

The above program will check the inserted string characters, and if the character matches the vowel character, it will add it to the string_1 set, and if the character is not a vowel, it will pass to the next.

Then we have put the condition that if the length of string_1 is not equal to the length of vowel_1, the string will not be accepted. But if the length of string_1 is equal to the length of vowel_1, it will accept the string.

Method 2:

Output:

Enter the String of characters: "aiD" 'OeiUo' fg "FGu" hs
The string is Accepted
Enter the String of characters: 'aidE' "I" 'eiIOo' "fgHYK" 'hs'
The string is Not Accepted

Explanation:

In the above code, we have use the condition that if the 0 is present in the vowel count array, the string will not be accepted. But if 0 is not present and the string contains all the vowels, the string will be accepted.

Method 3:

Output:

Enter the String of characters: gIrwi aTheDy uKmtR wmsof
The string is Accepted

Enter the String of characters:  aidc Eie iIOof gH YKhs
The string is Not Accepted

Explanation:

In the above code, we have use the condition that if the string's length is greater or equal to the length of the vowel_1, that is, 5, and contains all the vowels. Then it will accept the string; otherwise, it will not accept the string.

Conclusion

In this tutorial, we have shown how to write a Python program for accepting the string which contains all the vowel characters. The users can also use the same code for different types of conditions for particular characters. We have explained different methods for the same.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA