Program to print even length word from the given argument using Python

Introduction

In this section of python programming, we will print the words of even length in the given phrase.

Program to print even length word from the given argument

Program

input_string = "Welcome to GoCoding"
print("Input string is: "+input_string + "\n")


def even_len(i):
# String split
    i = i.split(' ')
    for strng in i:
# Check length is even
        if len(strng)%2 == 0:
            print(strng)
           
even_len(input_string)

Output

Program to print even length word from the given argument Output

Explanation

To achieve our task we have first split the phrase into words using split() and calculated the length of words using len(). If the length is found to be even the word is printed on the screen using print function.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.