Write A Python Program To Test Whether A Passed Letter Is A Vowel Or Not

The Python program accepts a letter from the user input and then checks if that letter is a vowel or not.

Your task is to compare the vowels with the user input letter, And print the result if the letter is a vowel or not a vowel.

 

Write A Python Program To Test Whether A Passed Letter Is A Vowel Or Not

 

 


Write A Python Program To Test Whether A Passed Letter Is A Vowel Or Not

Let's take a variable named as char,  ask user to enter a letter using the input function call  and take the first character of the particular letter if the user enters a string by mistake using index 0 [0]


Take another variable named as vowels and assign the string containing the vowels that are “aeiou” and “AEIOU”.

char = input("Enter a Letter : ")[0]

vowels = "aeiouAEIOU"





Use the if statement and check if the char is present in the ovals,  if the statement is true then print the letter is in vowel.  using the else block print the character is not a vowel.

if char in vowels:
   print(f"Letter {char} is a Vowel")
else:
   print(f"Letter {char} is not a Vowel")





Code
===============


char = input("Enter a Letter : ")[0]

vowels = "aeiouAEIOU"

if char in vowels:
   print(f"Letter {char} is a Vowel")
else:
   print(f"Letter {char} is not a Vowel")




Output
===========
Enter a Letter : A
Letter A is a Vowel




Output
=====================
Enter a Letter : hello
Letter h is not a Vowel




Output
==================
Enter a Letter : eva
Letter e is a Vowel



Output
===============
Enter a Letter : 2
Letter 2 is not a Vowel





Conclusion
==================
Execute the above program by  providing an English letter to the program.  note down the results.

Comment down below if you have any suggestions to improve the above Python program.






Post a Comment

0 Comments