Python Program to Calculate Cube of a Number

Python Program to Calculate Cube of a Number

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

  • 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   

Recommended Python Posts

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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