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

 

 

 

 

 

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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago