{"id":8247,"date":"2021-06-07T18:08:44","date_gmt":"2021-06-07T12:38:44","guid":{"rendered":"https:\/\/python-programs.com\/?p=8247"},"modified":"2021-11-22T18:38:38","modified_gmt":"2021-11-22T13:08:38","slug":"python-program-to-print-the-natural-numbers-summation-pattern","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-the-natural-numbers-summation-pattern\/","title":{"rendered":"Python Program to Print the Natural Numbers Summation Pattern"},"content":{"rendered":"
Natural Numbers:<\/strong><\/p>\n Natural numbers are a subset of the number system that includes all positive integers from one to infinity. Natural numbers, which do not include zero or negative numbers, are also known as counting numbers. They are a subset of real numbers that include only positive integers and exclude zero, fractions, decimals, and negative numbers.<\/p>\n Given a number the task is to print the natural numbers summation Pattern<\/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 There are several ways to print the natural numbers summation pattern in Python some of them are:<\/p>\n Drive into Python Programming Examples<\/a> and explore more instances related to python concepts so that you can become proficient in generating programs in Python Programming Language.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Mathematical formula for sum of n natural numbers\u00a0 :<\/p>\n ( numb * (numb+1) ) \/2<\/strong><\/p><\/blockquote>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Mathematical formula for sum of n natural numbers\u00a0 = ( numb * (numb+1) ) \/2<\/strong><\/p><\/blockquote>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Natural Numbers: Natural numbers are a subset of the number system that includes all positive integers from one to infinity. Natural numbers, which do not include zero or negative numbers, are also known as counting numbers. They are a subset of real numbers that include only positive integers and exclude zero, fractions, decimals, and negative …<\/p>\ngiven number = 7<\/pre>\n
1 = 1\r\n1 + 2 = 3\r\n1 + 2 + 3 = 6\r\n1 + 2 + 3 + 4 = 10\r\n1 + 2 + 3 + 4 + 5 = 15\r\n1 + 2 + 3 + 4 + 5 + 6 = 21\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 = 28<\/pre>\n
given number = 9<\/pre>\n
1 = 1\r\n1 + 2 = 3\r\n1 + 2 + 3 = 6\r\n1 + 2 + 3 + 4 = 10\r\n1 + 2 + 3 + 4 + 5 = 15\r\n1 + 2 + 3 + 4 + 5 + 6 = 21\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 = 28\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45<\/pre>\n
Program to Print the Natural Numbers Summation Pattern in Python<\/h2>\n
\n
Method #1: Using nested for loops (Static Input)<\/h3>\n
\n
# given number\r\nnumb = 15\r\n# traversing from 1 to numb using for loop\r\nfor i in range(1, numb+1):\r\n # taking a empty list\r\n emptylist = []\r\n # traversing from 1 to i\r\n for j in range(1, i+1):\r\n # printing the value of j\r\n print(j, sep=\" \", end=\" \")\r\n if(j < i):\r\n print(\"+\", sep=\" \", end=\" \")\r\n # appending\/adding the value to the empty list\r\n emptylist.append(j)\r\n # printing the sum of emptylist\r\n print(\"=\", sum(emptylist))\r\n<\/pre>\n
1 = 1\r\n1 + 2 = 3\r\n1 + 2 + 3 = 6\r\n1 + 2 + 3 + 4 = 10\r\n1 + 2 + 3 + 4 + 5 = 15\r\n1 + 2 + 3 + 4 + 5 + 6 = 21\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 = 28\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 = 66\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 = 78\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 = 91\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 = 105\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 = 120<\/pre>\n
\n
Method #2: Using nested for loops and mathematical formula (Static input)<\/h3>\n
\n
# given number\r\nnumb = 9\r\n# traversing from 1 to numb using for loop\r\nfor i in range(1, numb+1):\r\n # traversing from 1 to i\r\n for j in range(1, i+1):\r\n # printing the value of j\r\n print(j, sep=\" \", end=\" \")\r\n if(j < i):\r\n print(\"+\", sep=\" \", end=\" \")\r\n # calculating sum of the n natural numbers using mathematical formula\r\n naturalSum = (i*(i+1))\/\/2\r\n # printing the total sum\r\n print(\"=\", naturalSum)\r\n<\/pre>\n
1 = 1\r\n1 + 2 = 3\r\n1 + 2 + 3 = 6\r\n1 + 2 + 3 + 4 = 10\r\n1 + 2 + 3 + 4 + 5 = 15\r\n1 + 2 + 3 + 4 + 5 + 6 = 21\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 = 28\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45<\/pre>\n
Method #3: Using nested for loops and mathematical formula (User input)<\/h3>\n
\n
# given number\r\nnumb = input(\"Enter your desired number = \")\r\n# conveerting numb to integer using int() function\r\nnumb = int(numb)\r\n# traversing from 1 to numb using for loop\r\nfor i in range(1, numb+1):\r\n # traversing from 1 to i\r\n for j in range(1, i+1):\r\n # printing the value of j\r\n print(j, sep=\" \", end=\" \")\r\n if(j < i):\r\n print(\"+\", sep=\" \", end=\" \")\r\n # calculating sum of the n natural numbers using mathematical formula\r\n naturalSum = (i*(i+1))\/\/2\r\n # printing the total sum\r\n print(\"=\", naturalSum)\r\n<\/pre>\n
Enter your desired number = 9\r\n1 = 1\r\n1 + 2 = 3\r\n1 + 2 + 3 = 6\r\n1 + 2 + 3 + 4 = 10\r\n1 + 2 + 3 + 4 + 5 = 15\r\n1 + 2 + 3 + 4 + 5 + 6 = 21\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 = 28\r\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36\r\n1 +2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45<\/pre>\n
\n