{"id":12670,"date":"2021-10-01T11:00:21","date_gmt":"2021-10-01T05:30:21","guid":{"rendered":"https:\/\/python-programs.com\/?p=12670"},"modified":"2021-11-22T18:33:27","modified_gmt":"2021-11-22T13:03:27","slug":"python-program-to-print-each-word-of-a-sentence-along-with-number-of-vowels-in-each-word","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-each-word-of-a-sentence-along-with-number-of-vowels-in-each-word\/","title":{"rendered":"Python Program to Print each Word of a Sentence along with Number of Vowels in each Word"},"content":{"rendered":"
Given a sentence, the task is to print each word of a Sentence along with the number of vowels in each word.<\/p>\n
Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to print each word of a Sentence along with the number of vowels in each word.<\/p>\n Practice Java programming from home without using any fancy software just by tapping on this Simple Java Programs for Beginners<\/a> tutorial.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Given a sentence, the task is to print each word of a Sentence along with the number of vowels in each word. Examples: Example1: Input: Given word =’Hello this is BTechgeeks’ Output: The total number of vowels in the given word { hello } is 2 The total number of vowels in the given word …<\/p>\nGiven word ='Hello this is BTechgeeks'<\/pre>\n
The total number of vowels in the given word { hello } is 2\r\nThe total number of vowels in the given word { this } is 1\r\nThe total number of vowels in the given word { is } is 1\r\nThe total number of vowels in the given word { btechgeeks } is 3<\/pre>\n
Given word = 'good morning this is btechgeeks python coding platform'<\/pre>\n
The total number of vowels in the given word { good } is 2\r\nThe total number of vowels in the given word { morning } is 2\r\nThe total number of vowels in the given word { this } is 1\r\nThe total number of vowels in the given word { is } is 1\r\nThe total number of vowels in the given word { btechgeeks } is 3\r\nThe total number of vowels in the given word { python } is 1\r\nThe total number of vowels in the given word { coding } is 2\r\nThe total number of vowels in the given word { platform } is 2<\/pre>\n
Program to Print each Word of a Sentence along with the Number of Vowels in each Word in Python<\/h2>\n
\n
Method #1: Using For Loop (Static Input)<\/h3>\n
\n
# Give the sentence as static input and store it in a variable.\r\ngivnstrng = 'Hello this is BTechgeeks'\r\n# Convert the given string\/sentence to lowercase using the lower() function.\r\ngivnstrng = givnstrng.lower()\r\n# To break words from a sentence, use the string.split() method.\r\n# The words will be separated and kept in a list named \u2018wordslst'\r\nwordslst = givnstrng.split()\r\n# Create a list called vowelchars, which will hold all of the vowels in the English alphabet.\r\nvowelchars = ['a', 'e', 'i', 'o', 'u']\r\n# Iterate through the list of words and set up a counter to count\r\n# the number of vowels in each one.\r\nfor gvnword in wordslst:\r\n cntvowel = 0\r\n # Start a nested loop that iterates throughout the word in question,\r\n # checking whether any of the characters are vowels.\r\n for m in gvnword:\r\n # Increase the counter if a character is a vowel.\r\n if m in vowelchars:\r\n cntvowel = cntvowel+1\r\n # Print the current iteration's word and the value\r\n # of the counter corresponding with it\r\n # (which contains the sentence's number of vowels).\r\n print(\r\n 'The total number of vowels in the given word {', gvnword, '} is', cntvowel)\r\n<\/pre>\n
The total number of vowels in the given word { hello } is 2\r\nThe total number of vowels in the given word { this } is 1\r\nThe total number of vowels in the given word { is } is 1\r\nThe total number of vowels in the given word { btechgeeks } is 3<\/pre>\n
Method #2: Using For Loop (User Input)<\/h3>\n
\n
# Give the sentence as user input using input() and store it in a variable.\r\ngivnstrng = input('Enter some random sentence = ')\r\n# Convert the given string\/sentence to lowercase using the lower() function.\r\ngivnstrng = givnstrng.lower()\r\n# To break words from a sentence, use the string.split() method.\r\n# The words will be separated and kept in a list named \u2018wordslst'\r\nwordslst = givnstrng.split()\r\n# Create a list called vowelchars, which will hold all of the vowels in the English alphabet.\r\nvowelchars = ['a', 'e', 'i', 'o', 'u']\r\n# Iterate through the list of words and set up a counter to count\r\n# the number of vowels in each one.\r\nfor gvnword in wordslst:\r\n cntvowel = 0\r\n # Start a nested loop that iterates throughout the word in question,\r\n # checking whether any of the characters are vowels.\r\n for m in gvnword:\r\n # Increase the counter if a character is a vowel.\r\n if m in vowelchars:\r\n cntvowel = cntvowel+1\r\n # Print the current iteration's word and the value\r\n # of the counter corresponding with it\r\n # (which contains the sentence's number of vowels).\r\n print(\r\n 'The total number of vowels in the given word {', gvnword, '} is', cntvowel)\r\n<\/pre>\n
Enter some random sentence = good morning this is btechgeeks python coding platform\r\nThe total number of vowels in the given word { good } is 2\r\nThe total number of vowels in the given word { morning } is 2\r\nThe total number of vowels in the given word { this } is 1\r\nThe total number of vowels in the given word { is } is 1\r\nThe total number of vowels in the given word { btechgeeks } is 3\r\nThe total number of vowels in the given word { python } is 1\r\nThe total number of vowels in the given word { coding } is 2\r\nThe total number of vowels in the given word { platform } is 2<\/pre>\n
\n