Python Program to Calculate Cube of Number

Python Program to Calculate Cube of Number

The objective of this Python post, you will see various Python programs that cover the following:

  • 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

Now let’s see each one by one:

1: Python Program to find Cube of a Number

  • Take input number from the user
  • Calculate the cube of given number using * operator
  • Print cube of the given 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:  10 
Cube of 10 is 1000   

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

  • Take input number from the user
  • Calculate the cube of the given number using function
  • Print cube of the given number
# 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  

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

  • Take input number from the user
  • Calculate the cube of given number using Exponent Operator
  • print cube of the given number
# 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   

Leave a Reply

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