Write A Python Function That Extract The Vowels Letter And Their Repetition

Given an input string to a Python program,  the logic should remove all the vowels and their reputation in the given string and print the  string after removing the vowels.

Also let's print the vowels contained in the string. This should be done using the Python function.

 

 

Write A Python Function That Extract The Vowels Letter And Their Repetition



Write A Python Function That Extract The Vowels Letter And Their Repetition


Define a Python function named as purge()  and provide the argument as string.  take a  string variable containing a  string of vowels that is "aeiouAEIOU"

Now take two variables that are new_vowels and new_text.  iterate all the letters present in the original given string and  use the if statement to check if vowels are a consonant. Separate the vowels and the consonant by appending to its particular string as shown below

After the vowels are separated print the new text and vowel present in the original string.  You can also use a Return statement to return both the  string values.

def purge(text):
   vowels = "aeiouAEIOU"
   new_vowels = ""
   new_text = ""
   for letter in text:
       if letter in vowels:
           new_vowels += letter
       else:
           new_text += letter
   print("String After Extracting Vowels :", new_text)
   print("Vowels Extracted are :", new_vowels)






In the main program take a variable named as data and user input function call to ask a user to enter the string.  in the next statement call the function by passing the the user provided in pushing the argument to the function.


data = input("Enter a String : ")
purge(data)





Python complete  working code  
=================================


def purge(text):
   vowels = "aeiouAEIOU"
   new_vowels = ""
   new_text = ""
   for letter in text:
       if letter in vowels:
           new_vowels += letter
       else:
           new_text += letter
   print("String After Extracting Vowels :", new_text)
   print("Vowels Extracted are :", new_vowels)


data = input("Enter a String : ")
purge(data)





OUTPUT
===================


Enter a String : I Love Python
String After Extracting Vowels :  Lv Pythn
Vowels Extracted are : Ioeo




Output
===============

Enter a String : Write A Python Function That Extract The Vowels Letter And Their Repetition
String After Extracting Vowels : Wrt  Pythn Fnctn Tht xtrct Th Vwls Lttr nd Thr Rpttn
Vowels Extracted are : ieAouioaEaeoeeeAeieeiio




Output
==================

Enter a String : extracting the vowels
String After Extracting Vowels : xtrctng th vwls
Vowels Extracted are : eaieoe



Conclusion
====================

Execute the above program on by providing the random strings as a input to the Python program,  no doubt the results

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

 

 


Post a Comment

0 Comments