Dhanwin
Dhanwin
Worksheet-1
Date:17/032023
a) 3 , 5 b) 5, 8 c) 2, 3 d) 3, 3
5 In python function, the function calling another function is known as
and the function being called is
known _ _
print(“100+200”)
print(float())
12 Identify the module to which the following function load () belong to?
def fun():
global a
a=10
print(a)
a=5
fun()
print(a)
a) 10 b) 5 c) 5 d) 10
10 10 5 5
15 Value returning functions should be generally called from inside of an expression
a) True b) False
17 These are predefined functions that are always available for use. For using them we
don’t need to import any module
19 If you want to communicate between functions i.e. calling and called statement,
then you should use
c) 5 6 d) 5 5
12 5 7 7
63 6 6
14
Predict the output of the following code snippet:
def Execute(M):
if M%3==0:
return M*3
else:
return M+10;
def Output(B=2):
for T in range (0,B):
print(Execute(T),"*",end="")
print()
Output(4)
Output()
Output(3)
15. Find the output of the following program:
def ChangeIt(Text,C):
T=""
for K in range(len(Text)):
T=T+Text[K].lower();
T=T+C;
elif K%2==0:
T=T+Text[K].upper()
else:
T=T+T[K-1]
print(T)
OldText="pOwERALone"
ChangeIt(OldText,"%")
16 What possible outputs are expected to be displayed on screen at the time of execution
of the program from the following code? Also specify the maximum value that can be
assigned to each of the variables L and U.
import random
Arr=[10,30,40,50,70,90,100]
L=random.randrange(1,3)
U=random.randrange(3,6)
for i in range(L,U+1):
print(Arr[i],"@",end="")
i) 40 @50 @ ii) 10 @50 @70 @90 @
iii) 40 @50 @70 @90 @ iv) 40 @100 @
def disp(str):
m=' '
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
else:
if i%2==0:
m=m+str[i-1]
else:
m=m+"@"
print(m.swapcase())
disp('StudyBag$2021')
total=0
def add(a,b):
global total
total=a+b
print(total)
add(6,6)
print(total)
a) 12 b) 12 c) 0 d) None of these
12 0 12
def makenew(mystr):
newstr = " "
count = 0
for i in mystr:
if count%2 ==0:
newstr = newstr+i.lower()
else:
if i.islower():
newstr = newstr+i.upper()
else:
newstr = newstr+i
count +=1
newstr = newstr+mystr[:3]
print ("The new string is :", newstr)
makenew("cbseEXAMs@2022")
import random
L=[10,7,21]
X=random.randint(1,2)
for i in range(X):
Y=random.randint(1,X)
print(L[Y],"$",end=" ")
Statement1: Local Variables are accessible only within a function or block in which it
is declared.
def prog(name):
for x in name:
if x.isalpha():
print('Alphabet')
elif x.isdigit():
print('Digit')
elif x.isupper():
print('Capital Letter')
else:
print('Hello All')
prog('[email protected]')
a) 0 b) 2 c) 1 d) 3
def changer(p,q=10):
p=p/q
q=p%q
print(p,"#",q)
return p
a=200
b=20
a=changer(a,b)
print(a,"$",b)
a=changer(a)
print(a,"$",b)
def div(lst,n):
for i in range(0,n):
if lst[i]%5==0:
lst[i]+=5
else:
lst[i]=lst[i]//2
lt=[45,20,23,54,5]
div(lt, len(lt))
for i in lt:
print(i,end='#')
a) 50#25#11.5#27.0#10# b) 50#25#11#27#10#
c) 50#25#1#0#10# d) 225#100#1#0#25#