{"id":22655,"date":"2021-09-27T08:37:01","date_gmt":"2021-09-27T03:07:01","guid":{"rendered":"https:\/\/python-programs.com\/?p=22655"},"modified":"2021-11-22T18:35:38","modified_gmt":"2021-11-22T13:05:38","slug":"python-program-to-find-sum-of-series-11-122-233-3-nn-n-2","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-sum-of-series-11-122-233-3-nn-n-2\/","title":{"rendered":"Python Program to Find Sum of Series 1^1\/1!+2^2\/2!+3^3\/3!…+n^n\/n!"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Find Sum of Series 1^1\/1+2^2\/2+3^3\/3…+n^n\/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 series (1^1\/1!+2^2\/2!+3^3\/3!…+N^N\/N!)<\/strong> till the given number N 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 Remediate your knowledge gap by attempting the Python Code Examples<\/a> regularly and understand the areas of need and work on them.<\/p>\n In the previous article, we have discussed Python Program to Find Sum of Series 1^1\/1+2^2\/2+3^3\/3…+n^n\/n Given a number N and the task is to find the sum of series (1^1\/1!+2^2\/2!+3^3\/3!…+N^N\/N!) till the given number N in Python. Examples: Example1: Input: Given Number (Limit) = 6 Output: The above series sum till the given number N{ …<\/p>\n
\nGiven a number N and the task is to find the sum of series (1^1\/1!+2^2\/2!+3^3\/3!…+N^N\/N!)<\/strong> till the given number N in Python.<\/p>\nGiven Number (Limit) = 6<\/pre>\n
The above series sum till the given number N{ 6 } = 109.00833333333333<\/pre>\n
Given Number (Limit) = 15<\/pre>\n
The above series sum till the given number N{ 15 } = 541239.9325756768<\/pre>\n
Program to Find Sum of Series 1^1\/1!+2^2\/2!+3^3\/3!…+n^n\/n! in Python<\/h2>\n
\n
Method #1: Using For Loop (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the number N(limit) as static input and store it in a variable.\r\ngvn_numb = 6\r\n# Take a variable to say rsltseries_summ and initialize its value to 0.0\r\n# (Floating point number)\r\nrsltseries_summ = 0.0\r\n# Take another variable to say factl_rslt and initialize its value to 1\r\nfactl_rslt = 1\r\n# Loop from 1 to the given number using the for loop.\r\nfor itr in range(1, gvn_numb+1):\r\n # Inside the loop, multiply the iterator value with the above\u00a0factl_rslt and\r\n # store it in the same variable.\r\n factl_rslt *= itr\r\n # calculate the value of the iterator raised to the power itself and\r\n # divided by the above factorial result using the pow() function.\r\n # Store it in another variable.\r\n a = pow(itr, itr) \/ factl_rslt\r\n # Add the above result to the\u00a0rsltseries_summ and store it in the same variable.\r\n rsltseries_summ += a\r\n# Print the sum of series till the given number N.\r\nprint(\r\n \"The above series sum till the given number N{\", gvn_numb, \"} = \", rsltseries_summ)\r\n<\/pre>\n
The above series sum till the given number N{ 6 } = 109.00833333333333<\/pre>\n
Method #2: Using For loop (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the number N (Limit) 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 to say rsltseries_summ and initialize its value to 0.0\r\n# (Floating point number)\r\nrsltseries_summ = 0.0\r\n# Take another variable to say factl_rslt and initialize its value to 1\r\nfactl_rslt = 1\r\n# Loop from 1 to the given number using the for loop.\r\nfor itr in range(1, gvn_numb+1):\r\n # Inside the loop, multiply the iterator value with the above\u00a0factl_rslt and\r\n # store it in the same variable.\r\n factl_rslt *= itr\r\n # calculate the value of the iterator raised to the power itself and\r\n # divided by the above factorial result using the pow() function.\r\n # Store it in another variable.\r\n a = pow(itr, itr) \/ factl_rslt\r\n # Add the above result to the\u00a0rsltseries_summ and store it in the same variable.\r\n rsltseries_summ += a\r\n# Print the sum of series till the given number N.\r\nprint(\r\n \"The above series sum till the given number N{\", gvn_numb, \"} = \", rsltseries_summ)\r\n<\/pre>\n
Enter some Random Number = 15\r\nThe above series sum till the given number N{ 15 } = 541239.9325756768<\/pre>\n
\n