Python Program to Find Cube of a Number

27-Oct-2022

.

Admin

Python Program to Find Cube of a Number

Hi Dev,

Now, let's see post of Python Program to Find Cube of a Number. This tutorial will give you simple example of How to cube a number in python. In this article, we will implement a To Find Cube of a given number in Python. you will learn Cube of a Number in Python With Code Examples. follow bellow step for Write a python to print cube of any numbers.

let's see below simple example with output:

Example 1: Python Program to find Cube of a Number


# 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: 5

Cube of 5 is 125

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

# 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 : 8

Cube of 8 is 512

Example 3: Python program find a Cube of given number using Exponent Operator

# 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: 10

Cube of 10 is 1000

I hope it can help you...

#Python