Python Program to Find Cube of Number

Python program to find or calculate cube of number; Through this tutorial, i am going to show you how to find cube of number in python by program.

In this tutorial, i will write a python program to calculate or find and print cube of numbers using cube() function and exponent operator.

Python Program to Calculate Cube of Number

See the 3 ways to find or calculate cube of a number in python; as shown below:

  • Python Program to find Cube of a Number
  • Python program to find Cube of given number Using Cube() function
  • Python program find a Cube of given number using Exponent Operator

Python Program to find Cube of a Number

Let’s see the first simple python program to find cube of a number; as shown below:

# Python program to calculate cube of given number
# take input a number from user
num = int(input("Enter an any number: "))
# calculate cube using * operator
cb = num*num*num
# display result
print("Cube of {0} is {1} ".format(num, cb))

Output

Enter an any number:  10 
Cube of 10 is 1000   

Python program to find Cube of given number Using Cube() function

The second python program to find cube of a number using cube() function; as shown below:

# Python Program to Calculate Cube of a Number
def cube(num):
    return num * num * num
num = int(input("Enter an any number : "))
cb = cube(num)
print("Cube of {0} is {1}".format(num, cb))

Output

Enter an any number :  6 
Cube of 6 is 216  

Python program find a Cube of given number using Exponent Operator

The thired python program to find cube of a number using cube() function; as shown below:

# Python program to calculate cube of a number using Exponent Operator
# take input from user
num = int (input("Enter an any number: "))
# calculate cube using Exponent Operator
cb = num**3
# print
print("Cube of {0} is {1} ".format(num, cb))

Output

Enter an any number:  5 
Cube of 5 is 125   

Recommended Python Tutorials

Leave a Comment