Categories: Uncategorized

Program to check whether an Alphabet is Vowel or Consonant in Python|3 ways

Program to check whether an Alphabet is Vowel or Consonant in Python

In this article, we will discuss the concept of Program to check whether an Alphabet is Vowel or Consonant in Python

In this post, we are going to learn how to write a program to  check whether given English alphabet is Vowel or Consonant  using various ways in Python language

Program to check whether Vowel or consonant

Code to check given Alphabet is Vowel or consonant using If else

In this code, we are going to learn how to check  the given  English alphabet is Vowel or consonant using if-else in Python language

Program 1

#Python code to check whether a character is vowel or consonant
ch=input("Please enter the character as you wish: ")
#take input from the user
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'):
#if part - check whether the given character is vowels
   print("the given character ",ch," is  vowel"); 

#else part - displays whether the given character is consonant
else:
    print("the given character ",ch," is  consonant");

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

Case 1

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

Case 2

Please enter the character as you wish: t
the given character t is consonant

Code to check given Alphabet is Vowel or consonant using If elif else

In this code, we are going to learn how to check  the given  English alphabet is Vowel or consonant using if-elif-else in Python language

Program 2

#Python code to check whether a character is vowel or consonant
ch=input("Please enter the character 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 code is executed, it produces the following result

Case 1

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

Case 2

Please enter the character as you wish: n
the given character n is consonant

 

Code to check given Alphabet is Vowel or consonant using Ascii Value

In this code, we are going to learn how to check  the given  English alphabet is Vowel or consonant using Ascii value in Python language

Program 3

#Python code to check whether a character is vowel or consonant
ch=input("Please enter the character 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("the given character ",ch," is  vowel"); 

else:
    print("the given character ",ch," is  consonant");

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

Case 1

Please enter the character as you wish: y
the given character y is consonant

Case 2

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

 

 

 

Suggested post

if else in Python language

Operator in Python language

function  in python language

 

Similar post

Java program to print all alphabets in given range

C program to print all alphabets in given range

C++ program to print all alphabets in given range

 

Java program to print all alphabets using loops

C program to print all alphabets using loops

C++ program to print all alphabets using loops

 

Java program to find whether a character is Alphabet or Not

C++ program to find whether a character is Alphabet or Not

C program to check whether a character is Alphabet or Not

Python program to check whether a character is Alphabet or Not

 

 

Karmehavannan

Recent Posts

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

1 year ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

1 year ago

This website uses cookies.