How to Quantity Vowels in a String in Python


In this example we will show how to use collections to calculate the number of vowel letters in a string.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

str = input("Please input the string: ").lower()
vowels = set("aeiou")
count = 0
for letter in str:
    if letter in vowels:
        count += 1
print("The number of vowels in the string is: ", count)

Output:

Please input the string: Hello Python
The number of vowels in the string is: 3
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments