Python Projects

Counting Vowels in Statement with Python

PREREQUISITES

To Practice this Program, you should have a basic knowledge of the following Topics:

PYTHON-FUNCTIONSS

INPUT & PRINT FUNCTION

We will use Input & Print Function to collect & print data from the website user into variables.

md

STRING METHOD - COUNT

We will use count method to count specific strings in user input.

WHAT TO DO ?

Ask the Website User for any statement and count the each vowel(a,e,i,o,u) present in it.:

HOW TO DO ?

Following are the steps to do :

01.

ACCEPT STATEMENT

At First, We have to ask for statement from user with Input Function.

</p>
<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>print("Write a statement to know how many vowels it includes ? ")
line = input("").lower()
</pre>
</div>
02.

COUNT VOWELS

Now, We will count each vowel present in the string/statement given by the user with count method.

<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>
a = line.count("a")
e = line.count("e")
i = line.count("i")
o = line.count("o")
u = line.count("u")
</pre>
</div>
03.

PRINT RESULT

Finally, Print the addition of all the vowels.

<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>vowels = a + e + i + o + u
print("Above statement includes " + str(vowels) + " vowels in total. ")</pre>
</div>
Things We Covered
  • Accepting User Data (Input Function)
  • Counting the vowels (String Methods – Count)
  • Print/Output the Data (Print Function)

Posted by Akshay Gupta

Leave a Reply

Your email address will not be published. Required fields are marked *