Functions Exercises
Functions Exercises
- Exercises
What will the following code print?
def addEm(x,y,z):
print(x+y+z) #48
def prod(x,y,z):
return x* y*z
a=addEm(6,16,26)
b=prod(2,3,6)
print(a,b)
Output
48
None 36
Consider below given function headers.
Identify which of these will cause error and
why?
Python
EasyEasyEasy
What is the output of the following code?
a=1
def f():
a=10
print(a) #10
f()
print(a) #1
Output
10
1
What is the output of the following code?
num=1
def myfunc( ):
num=10
return num
print(num) #1
print(myfunc( )) #10
print(num) #1
Output
1
10
1
What is the output of the following code?
num=1
def myfunc( ):
global num
num=10
return num
print(num) #1
print(myfunc( )) #10
print(num) #10
Output
1
10
10
What is the output of the following code?
5
2
What is the output of the following code?
def func(x,y=100,z=1000):
print(„x=„,x,‟y=„,y,‟and z=„,z)
func(5,15,25)
func(35,z=55)
func(y=70,x=200)
Output
x= 5 y= 15 and z= 25
x= 35 y= 100 and z= 55
x= 200 y= 70 and z= 1000
What is the output of the following code?
def display(name,deptt,sal):
print(“Name”,name)
print(“Department”,deptt)
print(“Salary”,sal)
display(sal=10000,name=“Tavisha”,deptt=“IT”)
display(deptt=“HR”,name=“Dev”,sal=5000)
Output
Name Tavisha
Department IT
Salary10000
Name Dev
Department
HR Salary
5000
What is the output of the following code?