Count vowels in a string – Python Program

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.

Master the basics of data analysis in Python. Expand your skillset by learning scientific computing with numpy.

Take the course on Introduction to Python on DataCamp here https://bit.ly/datacamp-intro-to-python

Program on Github

You can also watch the video on YouTube here.

Task

Python program to count the number of each vowel 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.