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

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
>>>

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
>>>

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
>>>

Interview Questions

C Programming
C++ Programming
Basic Python Tutorial