0% found this document useful (0 votes)
4 views14 pages

Function Day6

The document contains multiple code snippets with their expected outputs. It includes function definitions, variable manipulations, and error identification related to function headers. Each snippet is followed by the anticipated output, demonstrating various programming concepts in Python.

Uploaded by

opradium
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views14 pages

Function Day6

The document contains multiple code snippets with their expected outputs. It includes function definitions, variable manipulations, and error identification related to function headers. Each snippet is followed by the anticipated output, demonstrating various programming concepts in Python.

Uploaded by

opradium
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

What will be the output of

the following snippets?


def changer(p,q=10):
p=p/q
q=q%q
print(p,"#",q)
return(p)
a=200
b=20
a=changer(a,b)
print(a,"$",b)
OUTPUT
10.0 # 0
10.0 $ 20
What will be the output of
the following snippets?
def func(L):
Times=0
Alpha=""
Add=0
for c in range(1,6,2):
Times=Times+c
Alpha=Alpha+L[c-1]+"$"
Add=Add+L[c]
print(Times,Add,Alpha)

Data=["P",20,"R",10,"S",30]
func(Data)
OUTPUT

9 60 P$R$S$
What will be the output of the
following snippets?
def func(L):
print(L[3:0:-1])
Data=[1,2,3,4,5]
func(Data)

(i) [4,3,2]
(ii) [4,3]
(iii) [4,3,2,1]
(iv) Syntax error
OUTPUT

(i) [4, 3, 2]
What will be the output of the
following snippets?
def fun():
l1=["Apple","Berry","Cherry","Papaya"]
l2=l1
l3=l1[:]
l2[0]="Guava"
l2[1]="Kiwi"
sum=0
for l in(l1,l2,l3):
if l[0]=="Guava":
sum+=1
if l[1]=="Kiwi":
sum=sum+20
print(sum)

fun()
OUTPUT

42
What will be the output of the
following snippets?
def dothis(x,I=[]):
for i in range(x):
I.append(i*i)
print(I)

dothis(2)
dothis(3,[3,2,1])
dothis(3)
OUTPUT
[0, 1]
[3, 2, 1, 0, 1, 4]
[0, 1, 0, 1, 4]
Identify which of these function
header will cause error and
why?
(i) def func (a=1,b):
(ii)def func(a=1,b,c=2):
(iii)def func(a=1,b=1,c=2):
(iv)def func(a=1,b=2,c=3,d):
FUNCTION HEADERS (I),(II),(IV) WILL
CAUSE ERROR BECAUSE NON DEFAULT
ARGUMENTS CAN’T FOLLOW DEFAULT
ARGUMENTS.
What will be the output of the
following snippets:
def add(x,y,z):
print(x+y+z)
def prod(x,y,z):
return(x*y*z)

a=add(6,16,26)
b=prod(2,3,6)
print(a,b)
OUTPUT
48
None 36

You might also like