Count Vowels in a String using Python

 

Topic: Count Vowels in a String using Python.

Hey Guys, today we are going see a Python Program to count vowels in a string using user input.

Title: Python Code for Counting Vowels in a String. (Beginner Friendly + Easy + Code + Output + Online Compiler)


What is this program and why we are going to use it?

This Program consists of Variables, Input Function, Loop (for loop) and Conditional Statements (if).

By using variables, we store string input from the user. By using input function, we take input from the user. For example:
s = "hello world"
Here s is a variable where "hello world" is assigned to s.

Vowels are: a, e, i, o, u (both lowercase and uppercase).

s = input("Enter a string: ")
So, this will ask user to input a string.

Logic:

1. Take a string (s) from user.
2. Initialize count = 0.
3. Define vowels = "aeiouAEIOU".
4. Loop through each character in the string.
   - If character is in vowels → increment count
5. Display total number of vowels.

Code:


Online Compiler (Switch to Interactive Mode before execution):



Example Output:

Input: hello world
Output: Number of vowels: 3

Applications:

1. Used in text processing and analysis
2. Helps in understanding string traversal
3. Useful in building basic NLP logic

Comments