program to count number of vowels using sets in given string


The program is a simple implementation of finding the number of vowels in a given string.

  • The first line of code initializes the string "Tutor Joes".
  • The second line initializes a variable count to 0, which will be used to count the number of vowels in the string.
  • The third line initializes a set called vowel with the vowels in uppercase and lowercase letters.
  • Then, the program uses a for loop to iterate over each character in the string str.
  • The loop checks if each character is in the set of vowels, and if it is, the count is incremented by 1.

Finally, the program prints the total number of vowels in the string.

Source Code

str = "Tutor Joes"	
count = 0
vowel = set("aeiouAEIOU")
print("String :",str)
print("Vowels :",vowel)
for alphabet in str:
	if alphabet in vowel:
		count = count + 1
 
print("Number of Vowels :", count)
 
 
 
 

Output

String : Tutor Joes
Vowels : {'A', 'a', 'i', 'U', 'o', 'u', 'I', 'E', 'O', 'e'}
Number of Vowels : 4