Python Program to Find Cube of a Number

In this post, we will learn how to find the cube of a number using Python Programming language.

The number that is obtained by multiplying an integer to itself three times is known as the cube of a number. For example: The cube of 2 is 2 x 2 x 2 = 8.

We will be using the following ways to find the cube of a number.

  1. Using Standard Method
  2. Using Exponent Method
  3. Using Functions

So, without further ado, let’s begin this tutorial.

Python Program to Find Cube of a Number

# Python Program to Find Cube of a Number
num = int(input("Enter an integer: "))

# Calculating cube
cube = num * num * num

# Displaying output
print("Cube of {0} is {1}" .format(num, cube))

Output

Enter an integer: 7
Cube of 7 is 343

How Does This Program Work ?

num = int(input("Enter an integer: "))

In this program, the user is asked to enter an integer.

# Calculating cube
cube = num * num * num

Then, we calculate the cube of the entered number by multiplying the number itself by three times.

# Displaying output
print("Cube of {0} is {1}" .format(num, cube))

Finally, the cube of the number is displayed on the screen using print() function.

Python Program to Find Cube of a Number Using Exponent

# Python Program to Find the Cube of a Number Using Exponent
num = int(input("Enter an integer: "))

# Calculating cube
cube = num ** 3

# Displaying output
print("Cube of {0} is {1}" .format(num, cube))

Output

Enter an integer: 6
Cube of 6 is 216

Python Program to Find Cube of a Number Using Functions

# Python Program to Find Cube of a Number Using Functions
def cube(num):
    return num * num * num 
    
num = int(input("Enter an number: "))

# Calling out function
cube_num = cube(num)

# Displaying output
print("Cube of {0} is {1}" .format(num, cube_num))

Output

Enter an number: 13
Cube of 13 is 2197

Conclusion

I hope after going through this post, you understand how to find the cube of a number using Python Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to solve your query.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *