Q:

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

0

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)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now