Skip to content
Home » Check Whether a Character is Vowel or Consonant using ASCII value Python

Check Whether a Character is Vowel or Consonant using ASCII value Python

Learn about Check Whether a character is Vowel or Consonant using ASCII value Python in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

Check Whether a character is Vowel or Consonant using ASCII value Python

The program prompts the user to enter an Alphabet, which is then stored in the character variable ch.
Using if-else expressions, the program determines whether the entered Alphabet is a vowel or a consonant.
If the supplied Alphabet begins with a vowel, The software outputs “it is a vowel” and if the provided Alphabet is not a vowel, it outputs “it is a consonant.”

Program:

# Program to check character is vowel or consonant

# character 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: G
G is a Consonant

Enter any character: E
E is a Vowel

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Python program to check character is vowel or consonant