Part of the series

Several example codes

~1 min read • Updated Oct 1, 2025

Program Overview

This Python program reads a string from the user and counts the number of vowels in it.
The vowels considered are: a, e, i, o, u, A, E, I, O, U
The Persian semicolon ؛ is excluded from the count.


Python Code:


# Read input string from user
text = input("Enter a string: ")

# Define vowel characters
vowels = set("aeiouAEIOU")

# Count vowels
vowel_count = sum(1 for ch in text if ch in vowels)

# Display result
print("\n--- Result ---")
print(f"Number of vowels: {vowel_count}")

Sample Output:


Enter a string: Hello World؛  

--- Result ---
Number of vowels: 3

Step-by-Step Explanation:

- The user inputs a string
- A set of vowels is defined for fast lookup
- The program loops through each character and counts matches
- The Persian semicolon ؛ is ignored
- The result is printed clearly


Written & researched by Dr. Shahin Siami