How to Create Count the Vowels in String in Python

In this tutorial, we will create a "How to Count the Vowels in a String in Python". We will cover the basics of creating this program to count the vowels in a string. Our goal is to understand the concept of counting vowels in a string and to display the accurate result. I will provide a sample program to demonstrate the actual coding of this tutorial.

This topic is simple and easy to understand; just follow the instructions I provide, and you can also do it yourself with ease. The program I will show you is how to count vowels in string. I will do my best to provide you with the easiest method of creating this program, called "Count the Vowels in string". So, let's start with the coding.

Getting Started:

First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python

Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console of counting the vowels in string. To do this, simply copy and paste these blocks of code into the IDLE text editor.
  1. def vowel_count(str):
  2. count = 0
  3. vowel = set("aeiouAEIOU")
  4. for alphabet in str:
  5. if alphabet in vowel:
  6. count = count + 1
  8. print("No. of vowels :", count)
  11. while True:
  12. ret=False
  14. print("\n\n================= Count the number of vowels in string =================\n\n")
  15. str = input("Enter your paragraph: ")
  18. vowel_count(str)
  20. user_input=input("\n\nTry again? (Yes/No): ")
  21. print("\n\n")
  22. if user_input.lower()=='no':
  23. print("Exit program.")
  24. break
  26. elif user_input.lower()=='yes':
  27. ret=True
  29. else:
  30. print("Wrong input.")
  31. ret=True
  34. if ret:
  35. continue

In the provided code, the first step is to create a method containing several blocks of code that handle the counting of vowels. We use a for loop to iterate through the string, checking each character to determine if it is a vowel, and then appending it to a variable.


The How to Create Count the Vowels in String in Python source code that I provide can be download below. Please kindly click the download button.

There you have it we successfully created How to Create Count the Vowels in String in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials

Add new comment