{"id":14764,"date":"2021-10-01T11:00:11","date_gmt":"2021-10-01T05:30:11","guid":{"rendered":"https:\/\/python-programs.com\/?p=14764"},"modified":"2021-11-22T18:33:27","modified_gmt":"2021-11-22T13:03:27","slug":"python-program-to-accept-a-sentence-and-print-only-the-first-letter-of-each-word-in-capital-letters-separated-by-a-full-stop","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-accept-a-sentence-and-print-only-the-first-letter-of-each-word-in-capital-letters-separated-by-a-full-stop\/","title":{"rendered":"Python Program to Accept a Sentence and Print only the First Letter of Each Word in Capital Letters Separated by a Full Stop"},"content":{"rendered":"
Don’t stop learning now. Get hold of all the important Java fundamentals with the Simple java program example<\/a> guide and practice well.<\/p>\n Given a string(sentence) the task is to Print only the First Letter of Each Word in Capital Letters Separated by a Full Stop in Python.<\/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 only the First Letter of Each Word in Capital Letters Separated by a Full Stop in Python.<\/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 Don’t stop learning now. Get hold of all the important Java fundamentals with the Simple java program example guide and practice well. Given a string(sentence) the task is to Print only the First Letter of Each Word in Capital Letters Separated by a Full Stop in Python. Examples: Example1: Input: Given string =hello this is …<\/p>\nGiven string =hello this is btechgeeks 21 python<\/pre>\n
H.T.I.B.P.<\/pre>\n
Given string =good morning this is btechgeeks online coding 24 platform for btech students<\/pre>\n
G.M.T.I.B.O.C.P.F.B.S.<\/pre>\n
Program to Accept a Sentence and Print only the First Letter of Each Word in Capital Letters Separated by a Full Stop in Python<\/h2>\n
\n
Method #1: Using For Loop (Static Input)<\/h3>\n
\n
# Give the sentence\/string as static input and store it in a variable.\r\ngvnstrng = 'hello this is btechgeeks 21 python'\r\n# Split the sentence into a list of words using the built-in spit() function.\r\ngvnstrngwords = gvnstrng.split()\r\n# Take an empty string to say resultstrng and initialize with the null value using \"\".\r\nresultstrng = \"\"\r\n# Traverse in this list of words using the For loop.\r\nfor strngword in gvnstrngwords:\r\n # Check if the word is alphabet or not using the If statement and isalpha() function\r\n if(strngword.isalpha()):\r\n # If it is true then, Convert the first letter of the word of\r\n # the string to the upper using the upper function and store it in a variable.\r\n firstchar = strngword[0].upper()\r\n # Concatenate dot character to the above variable using string concatenation.\r\n firstchar = firstchar+\".\"\r\n # Add this result to resultstrng using string concatenation.\r\n resultstrng = resultstrng+firstchar\r\n\r\n# Print resultstrng.\r\nprint(resultstrng)\r\n<\/pre>\n
H.T.I.B.P.<\/pre>\n
Method #2: Using For Loop (User Input)<\/h3>\n
\n
# Give the sentence\/string as user input using the input() function\r\n# and store it in a variable.\r\ngvnstrng = input('Enter some random string\/sentence = ')\r\n# Split the sentence into a list of words using the built-in spit() function.\r\ngvnstrngwords = gvnstrng.split()\r\n# Take an empty string to say resultstrng and initialize with the null value using \"\".\r\nresultstrng = \"\"\r\n# Traverse in this list of words using the For loop.\r\nfor strngword in gvnstrngwords:\r\n # Check if the word is alphabet or not using the If statement and isalpha() function\r\n if(strngword.isalpha()):\r\n # If it is true then, Convert the first letter of the word of\r\n # the string to the upper using the upper function and store it in a variable.\r\n firstchar = strngword[0].upper()\r\n # Concatenate dot character to the above variable using string concatenation.\r\n firstchar = firstchar+\".\"\r\n # Add this result to resultstrng using string concatenation.\r\n resultstrng = resultstrng+firstchar\r\n\r\n# Print resultstrng.\r\nprint(resultstrng)\r\n<\/pre>\n
Enter some random string\/sentence = good morning this is btechgeeks online coding 24 platform for btech students\r\nG.M.T.I.B.O.C.P.F.B.S.<\/pre>\n
\n