Python program to find cube of a number; In this tutorial, you will learn how to find or calculate cube of a number in python using function, exponent operator.
Python Program to Calculate Cube of a Number
Let’s use the following algorithm to write a python program to find the cube of a number:
- 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