Python Program to Count the Number of Vowels in a String

In the realm of programming, string manipulation is a fundamental skill. Counting the number of vowels in a string is a common programming task that helps to enhance your understanding of basic string operations and loops in Python. This program aims to demonstrate how to accomplish this task efficiently.

Problem Statement

Write a Python program that takes a string as input and calculates the total number of vowels present in the given string. The program should consider both uppercase and lowercase vowels.

Python Program to Count the Number of Vowels in a String

def count_vowels(string):
    vowels = "aeiouAEIOU"  # List of vowels, both lowercase and uppercase
    vowel_count = 0

    for char in string:
        if char in vowels:
            vowel_count += 1

    return vowel_count

# Input
input_string = input("Enter a string: ")

# Counting vowels
vowel_count = count_vowels(input_string)

# Output
print("The number of vowels in the given string:", vowel_count)

Input / Output

Python Program to Count the Number of Vowels in a String

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this python tutorial, you will learn how to Display Prime Numbers Between Two Intervals using the if and else...
In this python tutorial, you will learn how to Calculate Standard Deviation with built in functions of the python programming...
In this Python program, we will convert temperature values from Celsius to Fahrenheit. The Celsius and Fahrenheit scales are two...