This is a Python Program to count the number of vowels present in a string using sets
The program takes a string and creates a dictionary with key as first character and value as words starting with that character.
1. Enter a string and store it in a variable.
2. Initialize a count variable to 0.
3. Create a set containing vowels.
4. Use a for loop to traverse through the letters in the string.
5. Using an if statement, check if the letter in the string is equal to a vowel.
6. If it is equal, increment the vowel count.
7. Print the final count of the vowels.
8. Exit.
Here is source code of the Python Program to create a dictionary with key as first character and value as words starting with that character. The program output is also shown below.
s=raw_input("Enter string:") count = 0 vowels = set("aeiou") for letter in s: if letter in vowels: count += 1 print("Count of the vowels is:") print(count)
1. User must enter a string and store it in a variable.
2. The count variable is initialized to 0.
3. A set containing vowels is created using set().
4. A for loop is used to traverse through the letters in the string.
5. An if statement checks if the letter in the string is equal to a vowel.
6. If it is equal, the vowel count is incremented.
7. The final count of the vowels is printed.
Case 1: Enter string:Hello world Count of the vowels is: 3 Case 2: Enter string:Python Program Count of the vowels is: 3
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
- Apply for Python Internship
- Practice Programming MCQs
- Check Python Books
- Apply for Programming Internship
- Check Information Technology Books