Count the number of consonants in a string.

In this program, we will take a string as input and count the number of consonants in a string.

Steps to solve the program
  1. Take a string as input.
  2. Create a list containing all the vowels and a count variable and assign its value equal to zero.
  3. Use For loop to iterate over each character of the string.
  4. If the character is not in the vowels list add 1 to the count variable.
  5. Print the output.
				
					#Input string
string = "sqltools"
vowel = ["a","e","i","o","u","A","E","I","O","U"]
count = 0

for char in string:
    if char not in vowel:
        count += 1

#Printing output
print("Number of consonants: ",count)
				
			

Output :

				
					Number of consonants:  6
				
			

count the number of vowels in a string.

print characters at odd places in a string.

Leave a Comment