All Python Programs

All Programs

Basic Python Programs

Simple Python programs

If Condition Programs

If condition based Python Programs 

Looping based programs

program based on for loop, while loop, range

Searching and Sorting

Python Searching Programs
Python Sorting Programs

Python program to print square and cube of a number

Solution: with out using functions
Solution: using functions without passing arguments
Solution: using functions and by passing arguments
Solution: using multiple functions without passing arguments
Solution: using multiple functions and by passing arguments
Solution: using functions and by passing arguments and returning values


Solution : Without using function
Program/Source Code

Square and cube of a number

a=int(input("Enter any number "))
b=a*a
c=a*a*a
print("square = ",b)
print("cube = ",c)

Output:

Enter any number 5
square = 25
cube = 125
>>>



Solution : Using function Without Passing Arguments
Program/Source Code

Using function

#function definition

def cal():
    a=int(input("Enter any number "))
    b=a*a
    c=a*a*a
    print("square = ",b)
    print("cube = ",c)

#function calling

cal()

Output:

Enter any number 6
square = 36
cube = 216
>>>



Solution : Using function by Passing Arguments
Program/Source Code

#function definition

def cal(a):
    b=a*a
    c=a*a*a
    print("square = ",b)
    print("cube = ",c)

#function calling
a=int(input("Enter any number "))
cal(a)

Output:

Enter any number 4
square = 16
cube = 64
>>>



Solution : Using multiple function without Passing Arguments
Program/Source Code

Using multiple functions

#function definition

def square():
    a=int(input("Enter any number "))
    b=a*a
    print("square = ",b)

def cube():
    a=int(input("Enter any number "))
    c=a*a*a
    print("cube = ",c)


#function calling

square()
cube()

Output:

Enter any number 8
square = 64
Enter any number 3
cube = 27
>>>



Solution : Using multiple function by Passing Arguments
Program/Source Code

#function definition

def square(a):
    b=a*a
    print("square = ",b)

def cube(a):
    c=a*a*a
    print("cube = ",c)


#function calling
a=int(input("Enter any number "))
square(a)
cube(a)

Output:

Enter any number 5
square = 25
cube = 125
>>>



Solution: using functions and by passing arguments and returning values
Program/Source Code

#function definition
def cal(a):
    b=a*a
    c=a*a*a
    return b,c

#function calling
a=int(input("Enter any number "))
s,c=cal(a)
print("square = ",s)
print("cube = ",c)

Output:

Enter any number 9
square = 81
cube = 729
>>>

Previous :Python program to print sum of two numbers.
Next : Python program to print sum, product , difference and average of two numbers

You May Also Like:

Python program to check number is +ve or not.
Python Program to Find Factorial of Number Using Loop
C Language Program to Print Fibonacci Series
Python Program for Prime Number upto a limit
Python Program to check character is a lower case alphabet or not

Tutorials

Technical Questions

Interview Questions

C Programming
C++ Programming
Basic Python Tutorial
Advanced Python Tutorial
C Language
C++ Programming
Python programming

C Interview Questions
C++ Interview Questions
Python Interview Questions
HTML Interview Questions