Member-only story

Interview question: Count the numbers of vowels and consonants in a string of text

Crystal X
2 min readMay 10, 2023

--

If you are intending to get a job as a Python developer then you will no doubt be asked a few coding questions to test your knowledge of the language. One question that is likely to be asked is to count the number of vowels and consonants in a string of text.

There are several answers to this question, but I developed an answer to the question, as evidenced by the code in the screenshot below.

The solution to this interview question, written in psuedocode is:-

  1. Define the string,s.
  2. Define the array, vowels, as a list of vowels in the alphabet.
  3. Defined the array, consonants, as a list of the consonants in the alphabet.
  4. Define the variables, vowel_count and consenant_count, and initialise them to 0.
  5. Create a for loop that will iterate through the length of the string, s. If the iteration is a vowel then increment vowel_count by 1. If the iteration is a consonant then increment consenant_count by 1.

I looked on the internet and I found other ways to count the vowels and consonants in a string, but I prefer the method that I have just presented about. Feel free to experiment with the code and look for an algorithm that you prefer.

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.

No responses yet