Write a Python Program for cube sum of first n natural numbers

Write a Python Program for cube sum of first n natural numbers?

Write a Python Program for cube sum of first n natural numbers?

Program
def cube_sum_of_natural_numbers(n):
    if(n<=0):
        return 0
    else:
        total=sum([i**3 for i in range(1,n+1)])
        return total
    
if __name__=="__main__":
    num=int(input("Enter a number: "))
    if(num<=0):
        print("Please enter a positive integer.")
    else:
        p=cube_sum_of_natural_numbers(num)
        print(f"The cube sum of the first {num} natural numbers is: {p}")


Output:

Enter a number: 7
The cube sum of the first 7 natural numbers is: 784

Enter a number: 4
The cube sum of the first 4 natural numbers is: 100



More Questions


82 . Write a Python Program to calculate the natural logarithm of any number.
83 . Write a Python Program for cube sum of first n natural numbers?
84 . Write a Python Program to find sum of array.



For latest job updates join Telegram Channel: https://t.me/sateeshm