In this python program, we will learn how to calculate the sum of series 1³+2³+3³+….+n³.
Sum of series 1³+2³+3³+….+n³ = ( n (n+1) / 6)²
Here is the source code of the program to calculate the sum of series 1³+2³+3³+….+n³.
# Python Program to calculate the Sum of Series 1³+2³+3³+….+n³
# Using formula and math.pow() function
# Import Module
import math
# Take the Input From the User
number = int(input("Enter any Positive Number: "))
total = 0
# Calculation
total = math.pow((number * (number + 1)) /2, 2)
# Print the Output
print("The Sum of Series upto {0} = {1}".format(number, total))
Enter any Positive Number: 10
The Sum of Series upto 10 = 3025.0
# Python Program to calculate the Sum of Series 1³+2³+3³+….+n³
# Using formula and math.pow() Function and Display the Series
# Import Module
import math
# Take the Input From the User
number = int(input("Enter any Positive Number: "))
total = 0
# Calculation
total = math.pow((number * (number + 1)) /2, 2)
# Print the Output
print("The Sum of Series upto {0} = {1} ".format(number,total))
# Print the Calculation of Series
for i in range(1, number + 1):
if(i != number):
print("%d^3 + " %i, end = ' ')
else:
print("{0}^3 = {1}".format(i, total))
Enter any Positive Number: 10
The Sum of Series upto 10 = 3025.0
1^3 + 2^3 + 3^3 + 4^3 + 5^3 + 6^3 + 7^3 + 8^3 + 9^3 + 10^3 = 3025.0
# Python Program to Calculate the Sum of Series 1³+2³+3³+….+n³
# Using Recursion
# Define a Recursive Function
def sum_of_cubes_series(number):
if(number == 0):
return 0
else:
return (number * number * number) + sum_of_cubes_series(number - 1)
# Take the Input From the User
num = int(input("Enter any Positive Number: "))
total = sum_of_cubes_series(num)
print("The Sum of Series upto {0} = {1}".format(num, total))
Enter any Positive Number: 10
The Sum of Series upto 10 = 3025
Comments