Python Program for cube sum of first n natural numbers Last Updated : 24 Feb, 2025 Comments Improve Suggest changes Like Article Like Report We are given a number n and we need to print the sum of series 13 + 23 + 33 + 43 + .......+ n3 till the n-th term in python.Examples:Input: n = 5Output: 225Explanation: 13 + 23 + 33 + 43 + 53 = 225Let's discuss some of the ways to do it.Using Mathematical Formula: Most efficient solution is to use the direct mathematical formula which is (n ( n + 1 ) / 2) ^ 2, where n is the number of terms. Python n = 5 res = ((n * (n + 1)) // 2) ** 2 print(res) Output225 Explanation: ((n * (n + 1)) // 2) ** 2 gives us the sum of cubes of integers from 1 to n.Table of ContentUsing Brute Force approachUsing list comprehensionUsing Enumerate ListUsing Brute Force approachWe can iterate from 1 to n, computing the cube of each number and summing them, where n is the limit up to which the sum is required. Python n = 5 sum = 0 for i in range(1, n + 1): res += i ** 3 print(res) Output225 Explanation: iterate from 1 to n using for loop and sum += i**3, keeps on adding the the cubes of the numbers.Using generator expressionUse generator expression to generate a list of cubes for numbers from 1 to n, then apply the sum() function to get the total. This approach is concise and efficient, combining iteration and summation in a single line. Python n = 5 res = sum(i**3 for i in range(1, n + 1)) print(res) Output225 Explanation: i**3 for i in range(1, n + 1) creates a list of cubes of numbers from 1 to n and then sum() function returns the sum of all the elements inside the list.Using Enumerate ListIn this approach, we will use the enumerate list to find the cube sum of n natural numbers in one line. Python n = 5 res = sum([(i+1) ** 3 for i, _ in enumerate(range(n))]) print(res) Output225 Explanation: use list comprehension with enumerate(range(n)) to generate cubes of numbers from 1 to n.apply the sum() function to compute the total sum of cubes.underscore (_) in enumerate() is a throwaway variable since enumerate(range(n)) returns both index and value, but only the index (i) is used. Comment More infoAdvertise with us Next Article Python Program to Print the Natural Numbers Summation Pattern K kartik Follow Improve Article Tags : Python Programs DSA maths-cube Similar Reads Sum of squares of first N natural numbers - Python The goal here is to calculate the sum of squares of the first n natural numbers. The sum of squares is the result of adding up the squares of each number from 1 to n. For example, if n = 5, the sum of squares would be 12 + 22 + 32+ 42+52=55. Let's explore different methods to compute this sum effici 3 min read Python Program to Find the Sum of Natural Numbers Using While Loop Calculating the Sum of N numbers in Python using while loops is very easy. In this article, we will understand how we can calculate the sum of N numbers in Python using while loop.Calculate Sum of Natural Numbers in Python Using While LoopBelow are some of the examples by which we can see how we can 2 min read Python Program to Get Sum of cubes of alternate even numbers in an array Given an array, write a program to find the sum of cubes of alternative even numbers in an array.Examples:Input : arr = {1, 2, 3, 4, 5, 6}Output : Even elements in given array are2,4,6Sum of cube of alternate even numbers are 2**3+6**3 = 224Input : arr = {1,3,5,8,10,9,11,12,1,14}Output : Even elemen 5 min read Find Cube of a Number - Python We are given a number and our task is to find the cube of this number in Python. The cube of a number is calculated by multiplying the number by itself twice. For example, if the input is 3, then the output will be 3 * 3 * 3 = 27. In this article, we will learn different ways to find the cube of a n 2 min read Python Program to Print the Natural Numbers Summation Pattern Given a natural number n, the task is to write a Python program to first find the sum of first n natural numbers and then print each step as a pattern. Input: 5 Output: 1 = 11 + 2 = 31 + 2 + 3 = 61 + 2 + 3 + 4 = 101 + 2 + 3 + 4 + 5 = 15 Input: 10 Output: 1 = 1 1 + 2 = 3 1 + 2 + 3 = 6 1 + 2 + 3 + 4 = 2 min read Python - Sum of Cubes in List We are having a list we need to find sum of cubes of list. For example, n = [1, 2, 3, 4] we are given this list we need to find sum of cubes of each element of list so that resultant output should be 100.Using List Comprehension with sum()List comprehension with sum() allows us to compute sum of cub 2 min read Like