{"id":20070,"date":"2021-09-06T13:36:00","date_gmt":"2021-09-06T08:06:00","guid":{"rendered":"https:\/\/python-programs.com\/?p=20070"},"modified":"2021-11-22T18:36:28","modified_gmt":"2021-11-22T13:06:28","slug":"python-program-to-find-sum-of-series-11-31-51-7-1-n2","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-sum-of-series-11-31-51-7-1-n2\/","title":{"rendered":"Python Program to Find Sum of Series 1+1\/3+1\/5+1\/7+…..1\/(N+2)"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Find the Sum of Series 3+7+13+21…..+N<\/a><\/p>\n Given a number N and the task is to find the sum of the given series (1+1\/3+1\/5+1\/7+…..1\/(N+2))<\/strong>\u00a0for the given number 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 find the sum of the given series (1+1\/3+1\/5+1\/7+…..1\/(N+2))\u00a0<\/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 Find the best practical and ready-to-use Python Programming Examples<\/a> that you can simply run on a variety of platforms and never stop learning.<\/p>\n In the previous article, we have discussed Python Program to Find the Sum of Series 3+7+13+21…..+N Given a number N and the task is to find the sum of the given series (1+1\/3+1\/5+1\/7+…..1\/(N+2))\u00a0for the given number in Python. Examples: Example1: Input: Given Number = 25 Output: The total sum of the series till the given …<\/p>\nGiven Number = 25<\/pre>\n
The total sum of the series till the given number { 25 } = 2.2643528386481675<\/pre>\n
Given Number = 14<\/pre>\n
The total sum of the series till the given number { 14 } = 1.9551337551337549<\/pre>\n
Program to Find Sum of Series 1+1\/3+1\/5+1\/7+…..1\/(N+2) in Python<\/h2>\n
\n
Method #1: Using While Loop (Static Input)<\/h3>\n
\n
# Give the number N as static input and store it in a variable.\r\ngvn_numb = 25\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.0 (to get the floating-point number).\r\nresltsum = 0.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, Add 1 divided by k to the above-initialized resltsum and\r\n # store it in the same\u00a0variable resltsum.\r\n resltsum += 1\/k\r\n # Increment the value of k by 2 and store it in the same variable k.\r\n k += 2\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 { 25 } = 2.2643528386481675<\/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.0 (to get the floating-point number).\r\nresltsum = 0.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, Add 1 divided by k to the above-initialized resltsum and\r\n # store it in the same\u00a0variable resltsum.\r\n resltsum += 1\/k\r\n # Increment the value of k by 2 and store it in the same variable k.\r\n k += 2\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 = 14\r\nThe total sum of the series till the given number { 14 } = 1.9551337551337549<\/pre>\n
\n