Python Program to Calculate Cube of a Number

Write a Python Program to Calculate the Cube of a Number using Arithmetic Operators and Functions with an example.

Python Program to find Cube of a Number

This Python program allows users to enter any numeric value. Next, Python finds a Cube of that number using an Arithmetic Operator.

# Python Program to Calculate Cube of a Number

number = float(input(" Please Enter any numeric Value : "))

cube = number * number * number

print("The Cube of a Given Number {0}  = {1}".format(number, cube))

Python Cube of a number output

 Please Enter any numeric Value : 5
The Cube of a Given Number 5.0  = 125.0

Python Program to Calculate Cube of a Number Example 2

This Python cube number example is the same as above, but here, we are using the Exponent operator.

# Python Program to Calculate Cube of a Number

number = float(input(" Please Enter any numeric Value : "))

cube = number ** 3

print("The Cube of a Given Number {0}  = {1}".format(number, cube))
 Please Enter any numeric Value : 10
The Cube of a Given Number 10.0  = 1000.0

Python Program to find Cube of a Number using Functions

In this Python program for cube number code snippet, we are defining a function that finds the Cube of a given number.

# Python Program to Calculate Cube of a Number

def cube(num):
    return num * num * num

number = float(input(" Please Enter any numeric Value : "))

cub = cube(number)

print("The Cube of a Given Number {0}  = {1}".format(number, cub))
Python Program to Calculate Cube of a Number 3