1.
What possible outputs(s) are expected to be displayed on screen at the time of execution
of the program from the following code? Also specify the maximum values that can be
assigned to each of the variables Lower and Upper.
import random
AR=[20,30,40,50,60,70];
Lower =random.randint(1,4)
Upper =random.randint(2,5)
for K in range(Lower, Upper +1):
print (AR[K],end=”#“)
(i) 40# (ii) 40#50#60# (iii) 50# (iv) All
2. Find and write the output of the following Python code:
def Show(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)
Show('HappyBirthday')
3. Write a function LMove(Lst,n) in Python, which accepts a list Lst of numbers and n is a
numeric value by which all elements of the list are shifted to left.
Sample Input Data of the list
Lst= [ 10,20,30,40,12,11], n=2
Output Lst = [30,40,12,11,10,20]
4. What do you mean by keyword argument in python? Describe with example.
OR
What is scope of a variable in python and write basic scopes of variables in Python.
5. What possible outputs(s) are expected to be displayed on screen at the time of
execution of the program from the following code. Select which option/s is/are correct
import random
print(random.randint(15,25) , end=' ')
print((100) + random.randint(15,25) , end = ' ' ) 115-125
print((100) -random.randint(15,25) , end = ' ' ) 75-85
print((100) *random.randint(15,25) ) 1500-2500
(i) 15 122 84 2500 (ii) 21 120 76 1500
(iii) 105 107 105 1800 (iv) 110 105 105 1900
6. Predict the output of the following code.
def swap(P ,Q):
P,Q=Q,P
print( P,"#",Q)
return (P)
R=100
S=200
R=swap(R,S)
print(R,"#",S)
7. Write a function listchange(Arr)in Python, which accepts a list Arr of numbers , the
function will replace the even number by value 10 and multiply odd number by 5 .
Sample Input Data of the list is:
a=[10,20,23,45]
listchange(a,4)
output : [10, 10, 115, 225]
8. Differentiate between actual parameter(s) and a formal parameter(s) with a suitable
example for each.
OR
Explain the use of global key word used in a function with the help of a suitable example.
9. What possible outputs(s) are expected to be displayed on screen at the time of execution
of the program from the following code? Also specify the maximum values that can be
assigned to each of the variables Lower and Upper.
import random
AR=[20,30,40,50,60,70];
Lower =random.randint(1,3)
Upper =random.randint(2,4)
for K in range(Lower, Upper +1):
print (AR[K],end=”#“)
(i) 10#40#70# (ii) 30#40#50# (iii) 50#60#70# (iv) 40#50#70#
10. Find and write the output of the following Python code:
def Display(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)
Display('
[email protected]')