Python Write functions to find the square and cube of a given number

Here, we are going to execute a python program to discover the square and 3D shape of a given number by making capacities.

Given a number, and we need to compose client characterized capacities to locate the square and 3D square of the number is Python.

Example:

 Input:
    Enter an integer number: 6

    Output:
    Square of 6 is 36
    Cube of 6 is 216

Function to get square:

def  square (num):
	return (num*num)

Function to get cube:

def  cube (num):
	return (num*num*num)

Program:

# python program to find square and cube
# of a given number

# User defind method to find square 
def square (num):
	return  (num*num)

# User defind method to find cube
def cube (num) :
	return  (num*num*num) 

# Main code 
# input a number
number = int (raw_input("Enter an integer number: "))

# square and cube
print "square of {0} is {1}".format(number, square(number))
print "Cube of {0} is {1}".format(number, cube (number))

Output

 Enter an integer number: 6
    square of 6 is 36
    Cube of 6 is 216

Leave a Comment

error: Alert: Content is protected!!