Write a python program to check whether the first and last letters of the given word is vowel or not ?

1. Introduction

In this blog post, we'll explore a simple yet interesting Python program: checking if the first and last letters of a given word are vowels. This is a common string manipulation task that can be useful in various scenarios, such as in language processing or as a part of larger text analysis algorithms.

2. Program Steps

1. Define a list of vowels.

2. Get the first and last character of the input word.

3. Check if both characters are vowels.

3. Code Program

def check_vowels(word):
    # Define a list of vowels
    vowels = 'aeiouAEIOU'

    # Get the first and last character of the word
    first_char = word[0]
    last_char = word[-1]

    # Check if both the first and last characters are vowels
    return first_char in vowels and last_char in vowels

# Example usage
word = "Apple"
result = check_vowels(word)
print(f"Are the first and last letters of '{word}' vowels? {result}")

Output:

For the word 'Apple', the output will be True as both the first (A) and last (e) letters are vowels.

Explanation:

1. A list of vowels is defined to include all vowels in both lowercase and uppercase. This is used to check if a character is a vowel.

2. The first and last characters of the input word are extracted. In Python, accessing the characters is straightforward using indexing: word[0] for the first character and word[-1] for the last.

3. The program checks if both the first and last characters are present in the vowels list. The use of the and operator ensures that the function returns True only if both characters are vowels.

This program efficiently determines if both the first and last letters of a word are vowels, demonstrating basic string manipulation in Python.


Comments