Python is a versatile and most popular programming language. It is easy to learn and always known for its simplicity and readability. This is a simple program written in python to difference between vowel letters and consonants. Python programming language is mostly used for machine learning and automation. It’s widely used in various fields such as web development, data analysis, artificial intelligence, scientific computing, and automation, making it one of the most popular languages in the world today.
def check_vowel_or_consonant(char):
vowels = 'aeiouAEIOU'
if len(char) == 1 and char.isalpha():
if char in vowels:
return f"{char} is a vowel."
else:
return f"{char} is a consonant."
else:
return "Please enter a single alphabetic character."
# Example usage
char = input("Enter a character: ")
result = check_vowel_or_consonant(char)
print(result)
How the code works:
- vowels variable: It contains both uppercase and lowercase vowels.
- Input validation: The function checks if the input is a single alphabetic character using len(char) == 1 and char.isalpha().
- Vowel check: If the character is found in the vowels string, it is classified as a vowel.
- Consonant check: If the character is not a vowel, it’s considered a consonant.
Error handling: If the input is not a single alphabetic character, the function prompts the user to enter a valid input.
Leave a Reply