Python Functions | Functions with arguments and not returning any value

Functions with arguments and not returning any value

In this, we pass arguments to the function, but the function does not return any value.

Example:

Question:1
Python script to calculate and print sum of two numbers
Sol:

#function definition

def sum(p,q):
    s=p+q
    print("Sum = ",s)
    
#function calling
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
sum(a,b)

#Output:

Enter 1st no 10
Enter 2nd no 20
Sum = 30
>>>

Question:2
Python script to calculate and print the square of a number
Sol:

#function definition

def square(n):
    s=n*n
    print("Square = ",s)
    
#function calling
a=int(input("Enter any no "))
square(a)

#Output:

Enter any no 2
Square = 4
>>>

Question:3
Python script to calculate and print cube of a number
Sol:

#function definition

def cube(n):
    s=n*n*n
    print("Cube = ",s)
    
#function calling
a=int(input("Enter 1st no "))
cube(a)

Output:

Enter 1st no 5
Cube = 125
>>>

Visitor Counter

0056727