1.
Find the output of the following: (2)
def main ( ) :
Moves=[11, 22, 33, 44]
Queen=Moves
Moves[2]+=22
L=Len(Moves)
for i in range (L)
print(“Now@”, Queen[L-i-1], “#”, Moves [i] )
Ans.
Now @ 44 # 11
Now @ 55 # 22
Now @ 22 # 55
Now @ 11 # 44
(2)Write the output of the following Python program code: (2)
def ChangeList():
L=[] Answer: EA3n
L1=[]
L2=[] 4.What output will be generated when the following Python code
for i in range(1,10): is executed?
L.append(i)
for i in range(10,1,–2):
L1.append(i)
for i in range(len(L1)):
L2.append(L1[i]+L[i])
L2.append(len(L)-len(L1))
print(L2)
ChangeList()
Ans.
Output is: [11,10,9,8,7,4]
3.Observe the following Python code carefully and obtain the Answer: [11, 10, 9, 8, 7,
output, which will appear on the screen after execution of it.
print (a,'$',b)
b=Alter(b)
print (a,'$', b)
a=Alter(a)
print (a,'$',b) 3
Ans
6000 * 0
6000 $ 30
600 * 0
6000 $ 600
120000 * 0
120000 $ 600
5]
Ans.
The new string is: S1U3E5Ts
6.What is the output of the following
program :
def myfunc(a):
a = a + 2
a = a * 2 1.Kritika was asked to accept a list of even numbers but she did
return a not put
print myfunc(2) the relevant condition while accepting the list of numbers. You
(a) 8 (b) 16 (c) Indentation Error (d) Runtime Error are required to write a user defined function oddtoeven(L) that
accepts the List L as an argument and convert all the odd numbers
7.Find and write the output of the following python code: into even by multiplying them by 2 .
def Alter(x,y=20):
x=x*y
y=x%y
print (x,'*',y) Answer
return (x)
a=200 2. Write a generator function generatesq() that displays the
b=30 squareroots of numbers from 100 to n where n is passed as an
a=Alter(a,b) argument .
5.Write a function mul ( ) which accepts list L,
odd_L, even_L as its parameters. Transfer
all even values of list L to even_L and all odd
values of L to odd_L.
eg. If L = [10, 22, 24, 36, 37, 43, 51]
odd_L = [ 37, 43,51] and even_L = [ 10, 22, 24, 26
3. Write definition of a method
]
EvenSum(NUMBERS) to add those values in
the list of NUMBERS, which are odd. (3) 6.
Ans. Write the definition of a function reverse(X) in Python to display
def EvenSum(NUMBERS):
the elements in reverse order such that each displayed element
n=len(NUMBERS)
is twice of the original element of the list X.
s=0
for i in range(n):
if (i%2!=0): For example:
s=s+NUMBERS[i] if the input List X is [4,8,7,5,6,11,10] then the
print( s ) function produces output as –
20, 22, 12, 10, 14, 16, 8
4. Write definition of a method
MSEARCH(STATES) to display all the state
names from a list of STATES, which are def reverse(X):
starting with alphabet M. (2)
For example : for i in range(len(X)):
If the list STATES contains X[i]=X[i]*2
["MP","UP","WB","TN","MH","MZ","DL","BH","RJ"," X.reverse()
HR"] print(X)
The following should get displayed : MP
MH MZ 7.
Ans. Write a user defined function GenNum(a, b) to generate odd
def MSEARCH(STATES): numbers between a and b (including b)
for i in STATES:
def getNum(a,b):
if i[0]=='M':
print (i) for i in range(a,b+1):
if i%2==1:
print(i)