{"id":17902,"date":"2021-08-26T10:42:24","date_gmt":"2021-08-26T05:12:24","guid":{"rendered":"https:\/\/python-programs.com\/?p=17902"},"modified":"2021-11-22T18:37:12","modified_gmt":"2021-11-22T13:07:12","slug":"python-program-to-calculate-sum-of-series-1%c2%b32%c2%b33%c2%b3-n%c2%b3","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-sum-of-series-1%c2%b32%c2%b33%c2%b3-n%c2%b3\/","title":{"rendered":"Python Program to Calculate Sum of Series 1\u00b3+2\u00b3+3\u00b3+\u2026.+n\u00b3"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Find Isosceles Triangle Area<\/a> where n= nth term of a series.<\/p>\n Given the nth term of a series and the task is to calculate the sum of the cubes of a series.<\/p>\n Math Module :<\/strong><\/p>\n Python’s math module is a built-in module. By importing this module, we can perform mathematical computations.<\/p>\n Numerous mathematical operations like ceil( ),floor( ),factorial( ),mod( ),value of pi ,…..etc .can be computed with the help of math module.<\/p>\n math.pow() :<\/strong><\/p>\n The math. pow() method returns the value of x to the power of y.<\/p>\n It throws a ValueError if x is negative and y is not an integer.<\/p>\n Both arguments are converted to floats by this method.<\/p>\n Note:<\/strong> Using math.pow(1.0,x) or math.pow(x,0.0) always returns 1.0.<\/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 calculate the sum of the cubes of a given series.<\/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 Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program to Find Isosceles Triangle Area The general mathematical formula to calculate the sum of cubes of a series\u00a0 =\u00a0 ( n (n+1) \/ 6)\u00b2 where n= nth term of a series. Given the nth term of a series and the task is to calculate the sum …<\/p>\n
\nThe general mathematical formula to calculate the sum of cubes of a series\u00a0 =\u00a0 ( n (n+1) \/ 6)\u00b2<\/p>\nGiven n value = 13<\/pre>\n
The sum of cubes of a series with the given n value[ 13 ] = 8281.0<\/pre>\n
Given n value = 6<\/pre>\n
The sum of cubes of a series with the given n value[ 6 ] = 441.0<\/pre>\n
Program to Calculate Sum of Series 1\u00b3+2\u00b3+3\u00b3+\u2026.+n\u00b3<\/h2>\n
\n
Method #1: Using Mathematical Formula (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the nth term of a series as static input and store it in a variable.\r\nnum = 10\r\n# Calculate the sum of cubes of a series with a given nth term using the above\r\n# mathematical formula and math.pow() function.\u00a0\r\n# Store it in another variable.\r\ncube_sum = math.pow((num * (num + 1)) \/ 2, 2)\r\n# Print the sum of cubes of a given series with the given n value.\r\nprint(\r\n \"The sum of cubes of a series with the given n value[\", num, \"] =\", cube_sum)\r\n<\/pre>\n
The sum of cubes of a series with the given n value[ 10 ] = 3025.0<\/pre>\n
Method #2: Using Mathematical Formula (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the nth term of a series as user input using the int(input()) function and store it in a variable.\r\nnum = int(input(\"Enter some random variable = \"))\r\n# Calculate the sum of cubes of a series with a given nth term using the above\r\n# mathematical formula and math.pow() function.\u00a0\r\n# Store it in another variable.\r\ncube_sum = math.pow((num * (num + 1)) \/ 2, 2)\r\n# Print the sum of cubes of a given series with the given n value.\r\nprint(\r\n \"The sum of cubes of a series with the given n value[\", num, \"] =\", cube_sum)\r\n<\/pre>\n
Enter some random variable = 8\r\nThe sum of cubes of a series with the given n value[ 8 ] = 1296.0<\/pre>\n
\n