PYTHON PROGRAM THAT ASKS THE USER TO ENTER A WORD AND PRINTS OUT WHETHER THAT WORD CONTAINS ANY VOWELS


Write a program that asks the user to enter a word and prints out whether that word contains any vowels


CODE:

def vowels_str(string):

    s=""

    vowels="aeiouAEIOU"

    for i in range(len(string)):

        if string[i] in vowels:

            if string[i] not in s:

                s=s+string[i]

    if s!="":

        print("The string contains vowels")

    else:

        print("The string doesn't contain vowels")

    return s

str=input("Enter a string:")

print("Vowels in a given string :",vowels_str(str))


EXPLANATION:

In this code, we write a function to check whether the string contains any vowels.

Here we create an empty string(s="") and put set of all the vowels in the variable vowels.

Next using for loop we check if the entered string contains any vowels and then add that string to the empty string and also prints an appropriate message.

If the vowel is repeated in the string then we don't add that again to the empty string .

Finally we return the string s which contains the vowels present in the main string.

Now we need to call the function by passing a string as parameter.


OUTPUT:

           

Not only for a word we can also check whether a sentence has any vowels, by giving a sentence as an input.






Comments

Popular posts from this blog

PYTHON PROGRAM THAT USES FOR LOOP TO PRINT THE NUMBERS 8,11,14,17,20,.........,83,86,89

PYTHON PROGRAM THAT ASKS THE USER TO ENTER TWO STRINGS OF SAME LENGTH AND WILL ALTERNATE THE CHARACTERS OF THE TWO STRINGS.FOR EXAMPLE: abcde and ABCDE THEN THE PROGRAM WILL PRINT AaBbCcDdEe

PYTHON PROGRAM THAT ASKS USER FOR LARGE INTEGERS AND INSERTS COMMAS INTO IT ACCORDING TO THE STANDARD AMERICAN CONVENTION FOR COMMAS IN LARGE NUMBERS