Home » Python programs

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

Here, we are going to implement a python program to find square and cube of a given number by creating functions.
Submitted by IncludeHelp, on August 13, 2018

Given a number, and we have to write user defined functions to find the square and cube 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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.