Alphabet

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

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

  • In the program, the user is asked to enter an Alphabet and entered Alphabet is stored in character variable ch
  • The program evaluates whether the entered Alphabet is a vowel or consonant, using  if-else statements
  • If the given Alphabet is a vowel The program displays the output “it is a vowel” and if the given Alphabet is not vowel it will display”it is consonant”

 

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

  • In the program, the user is asked to enter an Alphabet and entered Alphabet is stored in character variable ch
  • The program evaluates whether the entered Alphabet is a vowel or consonant, using  ASCII value
  • If the given Alphabet is a vowel The program displays the output “it is a vowel” and if the given Alphabet is not vowel it will display”it is consonant”

 

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

  • In the program, the user is asked to enter an Alphabet and entered Alphabet is stored in character variable ch
  • The program evaluates whether the entered Alphabet is a vowel or consonant, using  pre-defined-function
  • If the given Alphabet is a vowel The program displays the output “it is a vowel” and if the given Alphabet is not vowel it will display”it is consonant”

 

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
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago