In this Python program, we will learn how to count the total number of the vowels in a string entered by the user.
Here is the source code of the program to count the total number of the vowels in a string entered by the user.
Python Program to Count the Total Number of Vowels in a String Using For Loop
# Python Program to Count the Total Number of Vowels in a String Using For Loop
# Take the Input From the User
str1 = input("Enter the String: ")
vowels = 0
for i in str1:
if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u' or i == 'A'
or i == 'E' or i == 'I' or i == 'O' or i == 'U'):
vowels = vowels + 1
print("Total Number of Vowels in this String = ", vowels)
Enter the String: Tutorialsrack is an Online Learning Website
Total Number of Vowels in this String = 16
Python Program to Count the Total Number of Vowels in a String using ASCII Value
# Python Program to Count the Total Number of Vowels in a String Using For Loop
# Take the Input from the User
str1 = input("Enter The String: ")
vowels = 0
for i in str1:
if(ord(i) == 65 or ord(i) == 69 or ord(i) == 73
or ord(i) == 79 or ord(i) == 85
or ord(i) == 97 or ord(i) == 101 or ord(i) == 105
or ord(i) == 111 or ord(i) == 117):
vowels = vowels + 1
print("Total Number of Vowels in this String = ", vowels)
Enter The String: Tutorialsrack is an Online Learning Website
Total Number of Vowels in this String = 16
Comments