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

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   

Recommended Python Posts

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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