{"id":19928,"date":"2021-09-02T15:20:19","date_gmt":"2021-09-02T09:50:19","guid":{"rendered":"https:\/\/python-programs.com\/?p=19928"},"modified":"2021-11-22T18:36:29","modified_gmt":"2021-11-22T13:06:29","slug":"python-program-to-find-sum-of-series-1-1-2-1-2-3-till-n","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-sum-of-series-1-1-2-1-2-3-till-n\/","title":{"rendered":"Python Program to Find Sum of Series (1+(1*2)+(1*2*3)+…till N)"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Find Sum of Series (1+(1+2)+(1+2+3)+…till N)<\/a> 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 find the sum of the given series (1+(1*2)+(1*2*3)+…till N)<\/strong> for the given number 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 If you wanna write simple python programs as a part of your coding practice refer to numerous Simple Python Program Examples<\/a> existing and learn the approach used.<\/p>\n In the previous article, we have discussed Python Program to Find Sum of Series (1+(1+2)+(1+2+3)+…till N) Given a number N and the task is to find the sum of the given series (1+(1*2)+(1*2*3)+…till N) for the given number in Python. Examples: Example1: Input: Given Number = 13 Output: The total sum of the series till …<\/p>\n
\nGiven a number N and the task is to find the sum of the given series (1+(1*2)+(1*2*3)+…till N) <\/strong>for the given number in Python.<\/p>\nGiven Number = 13<\/pre>\n
The total sum of the series till the given number { 13 } = 6749977113<\/pre>\n
Given Number = 7<\/pre>\n
The total sum of the series till the given number { 7 } = 5913<\/pre>\n
Program to Find the sum of series (1+(1*2)+(1*2*3)+…till N) in Python<\/h2>\n
\n
Method #1: Using While Loop (Static Input)<\/h3>\n
\n
# Give the number N as static input.\r\n# store it in a variable.\r\ngvn_numb = 13\r\n# Take a variable say resltsum which gives the sum of the given series till N and\r\n# initialize its value to 0.\r\nresltsum = 0\r\n# Take another variable say k and initialize its value with 1.\r\nk = 1\r\n# Loop until the value of k is less than or equal to the given number using the while loop.\r\nwhile(k <= gvn_numb):\r\n # Inside the loop take a variable say gvn_multiplr and initialize its value with 1.\r\n gvn_multiplr = 1\r\n # Iterate from 1 to the value of k using the for loop.\r\n for itr in range(1, k+1):\r\n # Multiply the iterator value to the above-initialized gvn_multiplr and store it in the same\r\n # variable gvn_multiplr.\r\n gvn_multiplr *= itr\r\n # Add the above-obtained value of gvn_multiplr to the resltsum outside the for loop.\r\n# Store it in the same variable resltsum.\r\n resltsum += gvn_multiplr\r\n # Increment the value of k by 1 outside the for loop.\r\n k += 1\r\n# Print the resltsum value which is the result of the series till the given Number N.\r\nprint(\r\n \"The total sum of the series till the given number {\", gvn_numb, \"} = \", resltsum)\r\n<\/pre>\n
The total sum of the series till the given number { 13 } = 6749977113<\/pre>\n
Method #2: Using While loop (User Input)<\/h3>\n
\n
# Give the number N as user input using the int(input()) function and\r\n# store it in a variable.\r\ngvn_numb = int(input(\"Enter some Random Number = \"))\r\n# Take a variable say resltsum which gives the sum of the given series till N and\r\n# initialize its value to 0.\r\nresltsum = 0\r\n# Take another variable say k and initialize its value with 1.\r\nk = 1\r\n# Loop until the value of k is less than or equal to the given number using the while loop.\r\nwhile(k <= gvn_numb):\r\n # Inside the loop take a variable say gvn_multiplr and initialize its value with 1.\r\n gvn_multiplr = 1\r\n # Iterate from 1 to the value of k using the for loop.\r\n for itr in range(1, k+1):\r\n # Multiply the iterator value to the above-initialized gvn_multiplr and store it in the same\r\n # variable gvn_multiplr.\r\n gvn_multiplr *= itr\r\n # Add the above-obtained value of gvn_multiplr to the\u00a0resltsum outside the for loop.\r\n# Store it in the same variable resltsum.\r\n resltsum += gvn_multiplr\r\n # Increment the value of k by 1 outside the for loop.\r\n k += 1\r\n# Print the resltsum value which is the result of the series till the given Number N.\r\nprint(\r\n \"The total sum of the series till the given number {\", gvn_numb, \"} = \", resltsum)\r\n<\/pre>\n
Enter some Random Number = 7\r\nThe total sum of the series till the given number { 7 } = 5913<\/pre>\n
\n