Python program to count vowels in a string

Hello everyone, welcome back to programminginpython.com! Here in this tutorial am going to tell how you can count vowels in a string, when an input string is received you will be able to count the number of vowels present in that string.

Program on Github

You can also watch the video on YouTube here.

Task

Python program to count number of each vowels in a given string.

Approach

  • Read an input string using input() or raw_input().
  • Declare vowels as a string vowels = 'aeiou'
  • Make the input string case insensitive using casefold() method
  • Create a dictionary with each vowel a key and value 0
  • Loop the string and check for vowels and if found increment the value in the dictionary
  • Print the result(dictionary)

Program

Output

Count vowels in a string - programminginpython.com
Count vowels in a string – programminginpython.com
Count vowels in a string - programminginpython.com
Count vowels in a string – programminginpython.com

Count Vowels in a String – Code Visualization

Course Suggestion

Machine Learning everywhere! So I strongly suggest you to take the course below.
Course: Machine Learning Adv: Support Vector Machines (SVM) Python

 

Feel free to check other python programs like sorting and searching algorithms or pattern programming and many more programs here.

Pattern Programming – Letter Series

Leave a Reply

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