Table of Contents
Introduction
In this section of python programing our task is to find and accept the strings which contains all the vowels in it ( i.e. a, e, i, o, u).
Program
Approach 1
def accpt(input_str): input_str1 = input_str.lower() vowel_set = ("aeiou") output_set = set({}) for i in input_str1: if i in vowel_set: output_set.add(i) else: pass if len(output_set) == len(vowel_set): print("All the vowels are present in the given string!") else: print("The string does not contain all the vowels!") input_str = input("Please enter the string : ") accpt(input_str)
Output
Approach 2
def accpt(input_string): input_string = input_string.replace(' ', ' ') input_string = input_string.lower() v_str = [input_string.count('a'), input_string.count('e'), input_string.count('i'), input_string.count('o'), input_string.count('u'), ] # Checking if any count is 0 if v_str.count(0) > 0: print("The string does not contain all the vowels!") else: print("All the vowels are present in the given string!") input_string = input("Please enter the string : ") accpt(input_string)
Output
Explanation
In the above python code we have used two approaches to achieve our task. In approach 1, we created a function accpt() which will check for all the characters in the given string and returns the output. Firstly we have converted all the characters of string to lower-case and created two sets: one set contains the all the 5 vowels and another one is empty set. For all the characters in the input string we are checking whether the character is in vowel set. If the value is present in vowel set then the character is appended to the empty set. After all the characters in the string are traversed, the length of vowel set and output set is checked against each other. If the length is found to be equal, the output “ All the vowels are present” is printed on the screen, otherwise “All the vowels are not present” is printed.
Similarly, in the second approach, we have taken the count of vowels present in the string in array v_str. If any of the count is 0 in array, the output “All the vowels are not present” is printed out else “All the vowels are present’ is printed on the screen.
0 Comments