Python Program to Check Vowel or Consonant

In this article, we will develop a python program to check vowel or consonant using different methods. In the English language, the letters A, E, I, O, U and a, e, i, o, u defined as a vowel. Except these all other letters are consonants.

Python Program to Check Whether a Character is Vowel or Consonant

This python program using the if-else statement to check character is vowel or consonant. We will take a character while declaring the variables. Then, check whether a character is a vowel or consonant using the if-else statement. Finally, the result will be displayed on the screen.

# Python program to check character is vowel or consonant

# take input
ch = input('Enter any character: ')

# check vowel or constant and display result
if(ch=='A' or ch=='a' or ch=='E' or ch =='e' or ch=='I' 
      or ch=='i' or ch=='O' or ch=='o' or ch=='U' or ch=='u'):
    print(ch, "is a Vowel")
else:
    print(ch, "is a Consonant")

Output for the different input values:-

Enter any character: a
a is a Vowel

Enter any character: g
g is a Consonant

Enter any character: I
I is a Vowel

Enter any character: T
T is a Consonant

Vowels and Consonant Program in Python

We can also use the built-in function to check if a character is vowels and consonants in python. We will take a character while declaring the variable. Then, check vowel and consonant using upper(), lower() function, and if-elif-else statement. Finally, the result will be displayed on the screen.

# Python program to check character is vowel or consonant

# take input
l = input('Enter any character: ')

# check vowel or constant and display result
if l.upper() in ('A', 'E', 'I', 'O', 'U'):
    print(l, "is a Vowel")
elif l.lower() in ('a', 'e', 'i', 'o', 'u'):
    print(l, "is a Vowel")
else:
    print(l, "is a Consonant")

Output:-

Enter any character: E
E is a Vowel

Check Vowels and Consonants using switch case

# Python program to check character is vowel or consonant

def isVowel(ch):  #user-defined function
    switcher = {
        'a': "Vowel",
        'e': "Vowel",
        'i': "Vowel",
        'o': "Vowel",
        'u': "Vowel",
        'A': "Vowel",
        'E': "Vowel",
        'I': "Vowel",
        'O': "Vowel",
        'U': "Vowel"
    }
    return switcher.get(ch, "Consonant")
 
# take input
ch = input('Enter any character: ')

# calling function and display result
print(ch,'is a '+isVowel(ch))

Output:-

Enter any character: r
r is a Consonant

using the ASCII values

In ASCII this is the respective values of every vowel both in lower and upper cases.

VowelDecimalHexa-DecimalBinary
A650x4101000001
E690x4501000101
I730x4901001001
O790x4F01001111
U850x5501010101
VowelDecimalHexa-DecimalBinary
a970x6101100001
e1010x6501100101
i1050x6901101001
o1110x6F01101111
u1170x7501110101

Check Whether a character is Vowel or Consonant using ASCII values

# Python program to check character is vowel or consonant

# take input
ch = input('Enter any character: ')

# check vowel or constant and display result
if(ord(ch) == 65 or ord(ch) == 69 or ord(ch) == 73 or ord(ch) == 79 
                  or ord(ch) == 85 or ord(ch) == 97 or ord(ch) == 101 
                   or ord(ch) == 105 or ord(ch) == 111 or ord(ch) == 117):
    print(ch, "is a Vowel")
else:
    print(ch, "is a Consonant")

Output:-

Enter any character: O
O is a Vowel

Also See:- Check If String Starts with Vowel in Python, Print Vowels in a String in Python, & Count Vowels in a String in Python

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *