Functions Worksheet-1
Functions Worksheet-1
WORKSHEET
-----------------------------------------------------------------------------------------------------------------------------------
1. What possible output is expected to be displayed on screen at the time of execution of
the program from the following code?
import random
AR=[22,33,44,55,66,77]
LOW=random.randint(1,3)
HIGH=random.randint(2,4)
for p in range(LOW,HIGH + 1):
print(AR[p],end=‟*‟)
(i)11*22*33* (ii)33*44*55* (iii) 55*66*77* (iv)44*55*66*
2. Find the Output:
M=”LIST”
L=[20,22,34,5]
D={ }
for I in range (len(M)):
if I %2==0:
D[L.pop()]=M[I]
else:
D[L.pop()]=I+3
for K,V in D.items():
print (K,V,sep=”#”)
3. Find the Output:
def update(a,b=5):
a=a//b
b=a%b
print(a, „$‟ ,b)
return a+b
a,b=100,30
a=update(a,b)
print(a, „#‟, b)
b=update(a,b)
4. Which is NOT the possible output of following program from given options:
import random
periph = ['Mouse', 'Keyboard', 'Printer', 'Monitor']
for i in range(random.randint(0,2)):
print(periph[i],'*',end=" ")
(A) Mouse *Keyboard * (B) Mouse *Keyboard* Printer*
(C) Mouse * (D) No output
5. Find and write the output of the following python code:
a=10
def call():
global a
a=15
b=20
print(a)
call()
print(a)
6. Find the output:
def samp(tup):
s=1
t=0
for i in range(s,4):
t=t+tup[i]
print(i,":",t)
t=t+tup[0]*10
print(t)
t=(10,30,15,9)
samp(t)
7. What are the possible outputs of the following program?
import random
text = "CBSEONLINE"
count = random.randint(0,3)
c=9
while text[c] != 'L':
print(text[c]+text[count]+'*',end=" ")
count= count + 1
c = c-1
i. EC* NB* IS* ii. NS* IE* LO*
iii. ES* NE* IO* iv. LE* NO* ON*
8. Find the output of the following code:
def showme(M,N):
for I in range(N):
if M[I]%5==0:
M[I]//=5
if M[I]%3==0:
M[I]//=3
Val=[25,8,55,12]
showme(Val,4)
for N in Val:
print (N,'#')
9. What will be the output of the following code:
def JumbleUp(mystr):
L = len(mystr)
str2= “ ”
str3= “ ”
for i in range(0,L,2):
str2=str2 + mystr[i+1]+mystr[i]
for ch in str2:
if ch>='R' and ch<='U':
str3+='$'
else:
str3+=ch.lower()
return str3
mystr="HARMONIOUS"
mystr=JumbleUp(mystr)
print(mystr)
10. What will the output of the following code?
def increment(n):
n.append([49])
return n[0],n[1],n[2],n[3] s
l=[23,35,47]
m1,m2,m3,m4=increment(l)
print(l)
print(m1,m2,m3,m4)
print(l[3]==m4)