In this tutorial, we are going to learn writing program in python to check if the character is a vowel ( a, e, i, o, u) or any other alphabet other than vowels(consonant).
Problem statement
For any input character, we have to check whether a character is a vowel or consonant.
[elementor-template id=”5253″]
For example:
Case 1: If a user is given input a or A
The output should be “Vowel”
As we know that A is a vowel
Case2: If the user is given b or B
The output should be “consonant”
As we know that B is consonant
[elementor-template id=”5257″]
Our logic to check given character is vowel or consonant
- Our program will take a character input from the user.
- Then using ‘in’ keyword our program will check if the input character is present in tuple of vowels.
- If the input character is present in the tuple of vowels then it prints the ‘Given character is vowel’.
- Else it prints ‘Given character is consonant’.
Algorithm to check given character is vowel or consonant
Step1 : Start
Step2 : Take input from user
Step3 : Apply the condition
if ch in vowel:
Print (‘vowel’)
else:
Print(’consonant’)
Step4 : Stop
Python code to check given character is vowel or consonant
Output 1:

Explanation
As we can see, for input “A” as ch , the output developed is “Given Character A is Vowel” , the ‘in’ keyword iterate through each elements of sequence (‘a’, ‘e’, ‘i’, ‘o’, ‘u’,’A’, ‘E’, ‘I’, ‘O’, ‘U’) and finally found the element “A” == ch, and return True. After this , the ‘if ’ block executed.
Output 2:

Explanation:
Similarly, As we can see, for input “h” as ch , the output developed is “Given Character A is consonant” , the ‘in’ keyword iterate through each elements of sequence (‘a’, ‘e’, ‘i’, ‘o’, ‘u’,’A’, ‘E’, ‘I’, ‘O’, ‘U’) and does not found the element “A” == ch, as ‘h’ does not exists in the sequence and return False. After this , the ‘else ’ block executed.