Python program to count the number of vowels in a string; Through this tutorial, i am going to show you how to count number of vowels in a string in python program.
In this tutorial, i will write a python program to count number of vowels using sets in given string using function, for loop and Ascii value.
How to count the vowels in a string in Python
See the following python program to count vowels in a string using function, for loop and ascii value; as shown below:
- 1: How to count number of vowels in a string in python using for loop
- 2: Python Program to Count Vowels in string Using For loop and Lower() function
- 3: Program to Count Total Number of Vowels in a String Using ASCII Value
1: How to count number of vowels in a string in python using for loop
- Get input string from the user in python program.
- Count vowels in string using for loop and if statement.
- Inside the For Loop, we are using If Statement to check whether the character is a, e, i, o, u, A, E, I, O, U. If true, increment the vowels value otherwise, skip that character.
- Print result.
# Python Program to Count Vowels in a String str1 = input("Please Enter Your Own 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)
After executing the program, the output will be:
Please Enter Your Own String : hello world Total Number of Vowels in this String = 3
2: Python Program to Count Vowels in string Using For loop and Lower() function
- Get input string from the user in python program.
- Convert string to lowercase using lower() function.
- Count vowels in string using for loop and if statement.
- Inside the For Loop, we are using If Statement to check whether the character is a, e, i, o, u. If true, increment the vowels value otherwise, skip that character.
- Print result.
# Python Program to Count Vowels in a String str1 = input("Please Enter Your Own String : ") vowels = 0 str1.lower() for i in str1: if(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)
After executing the program, the output will be:
Please Enter Your Own String : hello World Total Number of Vowels in this String = 3
3: Program to Count Total Number of Vowels in a String Using ASCII Value
- Get input string from the user in python program.
- Count vowels in string using for loop, if statement, and ord() function.
- Inside the For Loop, we are using If Statement to check whether the character is a, e, i, o, u, A, E, I, O, U by using ord() function. If true, increment the vowels value otherwise, skip that character.
- Print result.
# Python Program to Count Vowels in a String str1 = input("Please Enter Your Own 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)
After executing the program, the output will be:
Please Enter Your Own String : you are a good developer Total Number of Vowels in this String = 11
Recommended Python Tutorials
Recommended:-Python Palindrome Program
Recommended:-Python Program to Count Set Bits in a Number
Recommended:-Python Program for BMI Calculation
Recommended:-Python Program to Find Out Absolute Value
Recommended:-Python Random Number Generator Code
Recommended:-Python program for Zip, Zap and Zoom game
Recommended:-Python Program to Swap Two Numbers
Recommended:-Python Program to Find n-th term of Fibonacci Series
Recommended:-Python Program For Calculator
Recommended:-Python Program to Find Strong Number
Recommended:-Python Program to Convert cm to Feet and Inches
Recommended:-How to Reverse a List in Python
Recommended:-Python Program to Convert Celsius to Fahrenheit
Recommended:-Python Program to Find Standard Deviation
Recommended:-Python Program to Check Perfect Number
Recommended:-Python Program to Display Calendar
Recommended:-Python Program to Print Alphabets from A to Z