# Functions in Python

## Functions with arguments and not returning any value

### Write a python script (using functions) to take for two numbers calculate and print their sum?

```#function definition
def sum(n1,n2):
s=n1+n2
print("Sum = ",s)

#function calling
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
sum(a,b)```

Enter 1st no 25
Enter 2nd no 63
Sum = 88
>>>

### Write a python script (using functions) to take for three numbers calculate and print their product?

```#function definition
def prod(n1,n2,n3):
p=n1n2n3
print("Product = ",p)

#function calling
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 2nd no "))
prod(a,b,c)```

Enter 1st no 2
Enter 2nd no 6
Enter 2nd no 3
Product = 36
>>>

### Write a python script (using functions) to take for a number calculate and print its square and cube?

```#function definition
def cal(n):
s=nn     c=nn*n
print("square = ",s)
print("cube = ",c)
#function calling
a=int(input("Enter any no "))
cal(a)```

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

## function with arguments and returning value

Question:
Write a python script using function to calculate and print sum of two numbers?

#function definition
def sum(p,q):
s=p+q
return(s)

#function calling
n1=int(input(“Enter 1st no “))
n2=int(input(“Enter 2nd no “))
c=sum(n1,n2)
print(“sum = “,c)
#or
print(“sum = “,sum(n1,n2))

#### output:

Enter 1st no 25
Enter 2nd no 63
sum = 88
sum = 88
>>>

Question:
Write a python script using function to calculate and print square of a number?
#function definition
def square(n):
s=n*n
return(s)

#function calling
a=int(input(“Enter any no “))
b=square(a)
print(“Square = “,b)

Enter any no 5
Square = 25
>>>