Codeforcoding

Python code to check whether a character is vowel or consonant

Python code to check whether a character is a vowel or consonant

In this article, we will discuss the concept of Python code to check whether a character is a vowel or consonant

In this post, we are going to learn how to find whether the given alphabet is vowel or consonant in Python language

Python code to check whether a character is vowel or consonant
Vowel or consonant

Python code to check  a character is a vowel or consonant using if-else

The program allows the user to enter an Alphabet thereafter it will  check and display the result of the given Alphabet whether it is a vowel or consonant using the if-else statements in Python programming language

Program 1

#Python code to check whether a character is vowel or consonant ide3.7
ch=input("Please enter the character as you wish: ")

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("The given character ",ch," is  the vowel"); #display vowel

else:
    print("The given character ",ch," is  consonant");#display consonant

When the above program is executed, it produces the following result

case 1

Please enter the character as you wish: a
the given character is a vowel

 

case 2

Please enter the character as you wish: A
the given character is a vowel

 

case 3

Please enter the character as you wish: s
the given character is a consonant

 

Approach

 

Python code to check  a character is a vowel or consonant using Ascii value

The program allows the user to enter an Alphabet thereafter it will  check and display the result of the given Alphabet whether it is a vowel or consonant using the ASCII value in Python programming language

Program 2

#Python code to check whether a character is vowel or consonant
ch=input("Please enter the Alphabet as you wish: ")
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 vowel");#display vowels

elif (ord(ch)>=97 and ord(ch)<=122 or ord(ch)>=65 and ord(ch)==90):
    print(ch," is consonant");#display consonant

When the above program is executed, it produces the following result

case 1

Please enter the Alphabet as you wish: a
a is  vowel

 

case 2

Please enter the Alphabet as you wish: A
O is  vowel

 

case 3

Please enter the Alphabet as you wish: s
s is consonant

 

Approach

 

Check  a character is a vowel or consonant using the pre-defined  method

Program 3

The program allows the user to enter an Alphabet thereafter it will  check and display the result of the given Alphabet whether it is a vowel or consonant using the predefined function in Python programming language

#Python code to check whether a character is vowel or consonant
ch=input("Please enter the Alphabet as you wish: ")

if ch.lower() in('a','e','i','o','u'):
   print(ch," is  vowel"); 

elif ch.upper() in('A','E','I','O','U'):
    print(ch," is  vowel");

else:
    print(ch," is consonant")

When the above program is executed, it produces the following result

case 1

Please enter the Alphabet as you wish: a
a is vowel

 

Case 2

Please enter the Alphabet as you wish: E
E is vowel

 

Case 3

Please enter the Alphabet as you wish: M
M is consonant

 

Approach

 

Suggested for you

The operator in Python language

Data type in Python language

If-else statements in Python Language

Function in Python language

 

Similar post

C code to check whether the Alphabet is vowel or consonant

C++ code to check whether the Alphabet is vowel or consonant

Java  code to check whether the Alphabet is vowel or consonant

 

C code to check whether the character is Alphabet or not

C++ code to check whether the character is Alphabet or not

Java code to check whether the character is Alphabet or not

Python code to check whether the character is Alphabet or not

 

Java program to print all upper case and lower case Alphabets

C++ program to print all upper case and lower case Alphabets

C program to print all upper case and lower case Alphabets

Java code to print all upper case and lower case Alphabets between the given range

C++ code to print all upper case and lower case Alphabets between the given range

C code to print all upper case and lower case Alphabets between the given range

 

 

 

 

 

 

 

 

Check whether an Alphabet is vowel or consonant in C language
C++ program to print all upper case and lower case Alphabets
Exit mobile version