You are on page 1of 17

Assignment Cum CBSE Exams Previous Question Bank

PYTHON REVISION TOUR

1 What do you understand by the term Iteration? 1 SQP 2019


2 Write the names of any four data types available in Python. 2 2019 - Old
3 Which one of the following is the default extension of a Python file? 1 SQP 2022
a. .exe b. .p++ c. .py d. .p
4 Which of the following symbol is used in Python for comments? 1 SQP 2022
a. $ b. @ c. // d. #
5 Find the invalid identifier from the following 1 2022 Term 1
(a) name (b) class (c) section (d) break
6 Find the invalid identifier from the following 1 SQP 2022
a. none b. address c. Name d. pass
7 Find the invalid identifier from the following 1 SQP 2021
a) MyName b) True c) 2ndName d) My_Name
8 Write the type of tokens from the following: 1 SQP 2019
(i) if (ii) roll_no
9 Identify the valid keywords in Python from the following: 2 Comptt 2020
(i) Queue (ii) False (iii) in (iv) Number - Old
(v) global (vi) method (vii) import (viii) List
10 Which of the following is not a valid variable name in Python ? Justify reason for it not 1 Comptt 2020
being a valid name. – New
(i) 5Radius (ii) Radius_ (iii) _Radius (iv) Radius
11 Which of the following are keywords in Python ? 1 Comptt 2020
(i) break (ii) check (iii) range (iv) while New
12 Which of the following is an incorrect Logical operator in Python? 1 2022 Term 1
(a) not (b) in (c) or (d) and
13 Which of the following operator cannot be used with string data type? 1 SQP 2022
a. + b. in c. * d. /
14 Identify the valid arithmetic operator in Python from the following. 1 SQP 2021
a) ? b) < c) ** d) and
15 Which of the following is valid arithmetic operator in Python: 1 SQP 2019
(i) // (ii) ? (iii) < (iv) and
16 Which of the following are valid operators in Python ? 2 Comptt 2019
(i) += (ii) ^ (iii) in (iv) && - Old
(v) between (vi) */ (vii) is (viii) like
17 Which of the following is the correct output for the execution of the following : 1 2022 Term 1
print(5 + 3 ** 2 / 2) Python statement ?
(a) 32 (b) 8.0 (c) 9.5 (d) 32.0
18 Evaluate the following expression and identify the correct answer. 1 SQP 2022
16 - (4 + 2) * 5 + 2 ** 3 * 4
a. 54 b. 46 c. 18 d. 32
19 Evaluate the following expressions: 2 SQP 2021
a) 6 * 3 + 4**2 // 5 – 8
b) 10 > 5 and 7 > 12 or not 18 > 3
20 Identify the output of the following Python statements. 1 SQP 2022
x = 2
while x < 9:
print(x, end='')
x = x + 1
a. 12345678 b. 3456789 c. 2345678 d. 23456789
21 Identify the output of the following Python statements. 1 SQP 2022
b = 1
for a in range(1, 10, 2):
b += a + 2
print(b)
a. 31 b. 33 c. 36 d. 39
22 Find and write the output of the following python code: 1 SQP 2019
x = "abcdef"
i = "a"
while i in x:
print(i, end = " ")
23 What will be the output for the following Python statements ? 1 2022 Term 1
L = [10, 20, 30, 40, 50]
L = L + 5
print(L)
(a) [10, 20, 30, 40, 50, 5] (b) [15, 25, 35, 45, 55]
(c) [5, 10, 20, 30, 40, 50] (d) Error
24 Identify the output of the following Python statements 1 2022 Term 1
L = []
for i in range(4):
L.append(2*i+l)
print(L[:: -1])
(a) [7,5,3,1] (b) [9,7,5,3]
(c) [4,3,2,1] (d) [1,2,3,4]
25 Identify the output of the following Python statements 1 2022 Term 1
L1, L2 = [10, 15, 20, 25], []
for i in range(len(L1)) :
L2.insert( i, L1.pop())
print(L1, L2,sep="&")
(a) [] & [25, 20, 15, 10]
(b) [10, 15, 20, 25] & [25, 20, 15, 10]
(c) [10, 15, 20, 25 ]& [10, 15, 20, 25]
(d) [25, 20, 15, 10] & []
26 Which of the following option can be the output for the following Python code ? 1 2022 Term 1
Ll = [10,20,30,20,10]
L2 = []
for i in Ll:
if i not in L2:
L2.append(i)
print(Ll, L2, sep="&")
(a) [10,20,30,20,10]&[10,20,30,20,10]
(b) [10,20,30,20,10][10,20,30,20,10]&
(c) [10,20,30,20,10]&[30,20,10]
(d) [10,20,30,20,10]&[10,20,30]
27 Identify the output of the following Python code : 1 2022 Term 1
D={l:"One", 2:"Two", 3: "Three"}
L=[]
for K,V in D.items():
if V[0]=="T":
L.append(K)
print(L)
(a) [1,2,3] (b) ["One", "Two", "Three"]
(c) [2,3] (d) ["Two", "Three"]
28 What will be the output of the following Python code ? 1 2022 Term 1
L = [10, 20]
L1=[30, 40]
L2=[50, 60]
L.append(L1)
L.extend(L2)
print(L)
(a) [60, 50, 40, 30, 20, 10] (b) [10, 20, 30, 40, 50, 60]
(c) [10, 20, 30, 40, [50, 60]] (d) [10, 20, [30, 40], 50, 60]
29 Identify the output of the following Python statements. 1 SQP 2022
x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)
a. 11.0 b. 12.0 c. 14.0 d. 15.0
30 Identify the output of the following Python statements. 1 SQP 2022
lst1 = [10, 15, 20, 25, 30]
lst1.insert( 3, 4)
lst1.insert( 2, 3)
print (lst1[-5])
a. 2 b. 3 c. 4 d. 20
31 Write the output of the following Python code : 1 Comptt 2020
for i in range(2,7,2): - New
print(i * '$')
32 Write the names of the immutable data objects from the following: 1 Comptt 2020
(i) List (ii) Tuple (iii) String (iv) Dictionary - New
33 Given the lists L = [1,3,6,82,5,7,11,92] , 1 SQP 2021
write the output of print(L[2:5])
34 Identify the valid declaration of L: 1 SQP 2021
L = [‘Mon’, ‘23’, ‘hello’, ’60.5’]
a. dictionary b. string c.tuple d. list
35 Identify the valid declaration of L: 1 SQP 2019
L = [1, 23, ‘hi’, 6]
(i) list (ii) dictionary (iii) array (iv) tuple
36 Which of the options out of (i) to (iv) is the correct data type for the variable Vowels as 1 Comptt 2020
defined in the following Python statement ? New
Vowels = ('A', 'E', 'I', 'O', 'U')
(i) List (ii) Dictionary (iii) Tuple (iv) Array
37 Consider the declaration L = 1, 'Python', '3.14'. 1 SQP 2022
What will be the data type of L?
a. list b. tuple c. dictionary d. string
38 Which of the following is not a Tuple in Python ? 1 2022 Term 1
(a) (1,2,3) (b) ("One", "Two", "Three")
(c) (10 ,) (d) ("One")

39 What will be the output for the following Python statements ? 1 2022 Term 1
T=(10,20,[30,40,50],60,70)
T[2][1]= 100
print(T)
(a) (10, 20, 100, 60, 70)
(b) (10, 20, [30,100,50], 60, 70)
(c) (10, 20, [100,40,50], 60, 70)
(d) Error
40 Nitish has declared a tuple T in Python as following : 1 2022 Term 1
T = (10, 20, 30)
Now he wants to insert an element 40 after these three elements of T so that the tuple
may contain (10, 20, 30, 40).
Which of the following statements shall Nitish write to accomplish the above task
(a) T = T + 40
(b) T = T + (40)
(c) T = T + (40,)
(d) Nitish cannot insert 40 into the tuple since Tuples are immutable
41 Given an object obj1= (10, 20, 30, 40, 50, 60, 70, 80, 90). 1 SQP 2022
What will be the output of print(obj1[3:7:2])?
a. (40,50,60,70,80) b. (40,50,60,70)
c. (40,50,60) d. (40,60)
42 Given an object obj1 = (10, 15, 25, 30). 1 SQP 2022
Identify the statement that will result in an error.
a. print(obj1[2]) b. obj1[2] = 20
c. print(min(obj1)) d. print(len(obj1))
43 What is the output of the following code? 1 SQP 2022
T=(100)
print(T*2)
a. Syntax error b. (200,) c. 200 d. (100,100)
44 Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect? SQP 2021
a) print(T[1]) b) T[2] = -29
c) print(max(T)) d) print(len(T))
45 A tuple is declared as 1 SQP 2021
T = (2,5,6,9,8)
What will be the value of sum(T)?
46 What will be the output of the following Python code ? 1 2022 Term 1
S="UVW"
L=[10,20,30]
D={}
N=len(S)
for I in range(N):
D[L[I] = S[I]
for K,V in D.items():
print (K,V, sep="*" ,end=",")
(a) U*10,V*20,W*30, (b) 10*U,20*V,30*W,
(c) 10,20,30,U*V*W* (d) Error
47 What will be the output for the following Python statements ? 2022 Term 1
D = {"AMIT":90,"RESHMA":96,"SUKHBIR":92,"JOHN":95}
print("JOHN" in D, 90 in D, sep = "#")

(a) Truef#False (b) True#True (c) False#True (d)False#False


48 Identify the output of the following Python statements : 1 2022 Term 1
D={}
T=("ZEESHAN","NISHANT","GURMEET","LISA")
for i in range(1, 5):
D[i]=T[i-l]
print(D)

(a) {"ZEESHAN","NISHANT","GURMEET","LISA"}
(b) "ZEESHAN","NISHANT","GURMEET","LISA"
(c){[1,"ZEESHAN"],[2,"NISHANT"],[3,"GURMEET"],[4,"LISA"]}
(d) {1:"ZEESHAN",2:"NISHANT",3:"GURMEET",4:"LISA"}
49 Which of the following statements is false in the context of dictionary? 1 SQP 2022
a) The values of a dictionary can be accessed using keys.
b) The keys of a dictionary can be accessed using values.
c) Elements in a dictionary are in form of key:value pairs.
d) Dictionaries are mutable.
50 Write a statement in Python to declare a dictionary whose keys are 1, 2, 3 and values 1 SQP 2021
are Monday, Tuesday and Wednesday respectively.
51 Which is the correct form of declaration of dictionary? 1 SQP 2019
(i) Day={1:’monday’,2:’tuesday’,3:’wednesday’}
(ii) Day=(1;’monday’,2;’tuesday’,3;’wednesday’)
(iii) Day=[1:’monday’,2:’tuesday’,3:’wednesday’]
(iv) Day={1’monday’,2’tuesday’,3’wednesday’]
52 Write a Python statement to declare a Dictionary named ClassRoll with Keys as 1, 1 Comptt 2020
2, 3 and corresponding values as 'Reena', 'Rakesh', 'Zareen' respectively. - New
53 Given the Python declaration S1 = "Hello". Which of the following statements will give 1 2022 Term 1
an error ?
(a) print(S1[4]) (b) S2=S1 (c) S1=S1[4] (d) S1[4]="Y"
54 22. Which of the following is not a valid Python string operation ? 1 2022 term 1
(a) 'Welcome' + '10' (b) 'Welcome' * 10
(c) 'Welcome' * 10.0 (d) "10" + 'Welcome'
55 Identify the output of the following Python statements 1 2022 term 1
S = "GOOD MORNING"
print(S.capitalize(),S.title(),end="!")

(a) GOOD MORNING!Good morning


(b) Good Morning!Good morning
(c) Good morning!Good Morning!
(d) Good morning Good Morning!
56 For a given declaration in Python as 1 2022 Term 1
s= "WELCOME"
Which of the following will be the correct output of
print (S [1: :2])?
(a) WEL (b) COME (c) WLOE (d) ECM
57 If the following code is executed, what will be the output of the following code? 1 SQP 2021
name="ComputerSciencewithPython"
print(name[3:10])
58 Find the output of the following code: 1 SQP 2022
Name="PythoN3@1"
R=""
for x in range(len(Name)):
if Name[x].isupper():
R=R+Name[x].lower()
elif Name[x].islower():
R=R+Name[x].upper()
elif Name[x].isdigit():
R=R+Name[x-1]
else:
R=R+"#"
print(R)

a. pYTHOn##@ b. pYTHOnN#@ c. pYTHOn#@ d. pYTHOnN@#


59 Find and write the output of the following Python code: 2 Comptt 2019
Str1="EXAM2018" - Old
Str2=""
I=0
while I<len(Str1):
if Str1[I]>="A" and Str1[I]<="M":
Str2=Str2+Str1[I+1]
elif Str1[I]>="0" and Str1[I]<="9":
Str2=Str2+ (Str1[I-1])
else:
Str2=Str2+"*"
I=I+1
print(Str2)
60 Rewrite the following code in Python after removing all syntax error(s). Underline each 2 SQP 2021
correction done in the code.
Value=30
for VAL in range(0,Value)
If val%4==0:
print (VAL*4)
Elseif val%5==0:
print (VAL+3)
else
print(VAL+10)
61 Rewrite the following code in python after removing all syntax error(s). Underline each 2 SQP 2019
correction done in the code.
30=To
for K in range(0,To)
IF k%4==0:
print(K*4)
Else:
print(K+3)
62 Rewrite the following code in Python after removing all syntax error(s). Underline each 2 Comptt 2020
correction done in the code. - Old
W = input('Enter a word')
If W <> 'HELLO':
print(W + 2)
else
print(W * 2)
63 Rewrite the following code in Python after removing all syntax error(s). Underline each 2 Comptt 2020
correction done in the code. - New
input('Enter a word',W)
if W = 'Hello'
print('Ok')
else:
print('Not Ok')
64 Rewrite the following code in Python after removing all syntax error(s). Underline each 2 Comptt 2019
correction done in the code. - Old
"HELLO"=String
for I in range(0,len(String)–1)
if String[I]=>"M":
print(String[I],"*")
Else:
Print(String[I-1])
65 Rewrite the following code in python after removing all syntax error(s). Underline each 2 2019 - Old
correction done in the code.
250 = Number
WHILE Number<=1000:
if Number=>750:
print(Number)
Number=Number+100
else
print(Number*2)
Number=Number+50
Assignment Cum CBSE Exams Previous Question Bank

FUNCTIONS

1 Name the built-in mathematical function / method that is used to return an absolute 1 SQP 2021
value of a number.
2 Name the Python Library modules which need to be imported to invoke the following 1 SQP 2019
functions: (i) sin() (ii) randint ()
3 Name the Python Library modules which need to be imported to invoke the following 1 Comptt 2020
functions: (i) floor() (ii) random() - Old
4 Name the Python Library modules which need to be imported to invoke the following 1 Comptt 2020
functions : (i) cos() (ii) randint() - New
5 Name the Python Library modules which need to be imported to invoke the following 1 Comptt 2019
functions: (i) open() (ii) factorial() - Old
6 Name the Python Library modules which need to be imported to invoke the following 1 2019 - Old
functions : (i) sqrt() (ii) start()
7 Which of the following is not correct in context of Positional and Default parameters in 1 2022 Term 1
Python functions ?
(a) Default parameters must occur to the right of Positional parameters
(b) Positional parameters must occur to the right of Default parameters
(c) Positional parameters must occur to the left of Default parameters
(d) All parameter to the right of a Default parameter must also have default values.
8 Which of the following is not correct in context of scope of variables ? 1 2022 Term 1
(a) global keyword is used to change value of a global variable in a local
(b) local keyword is used to change value of a local variable in a global scope
(c) global variable can be accessed without using the global keyword in a local scope
(d) local variables cannot be used outside its scope
9 Which of the following is not a function/method of the random module in python 1 2022 Term 1
(a) randfloat() (b) randint() (c) random() (d) randrange()
10 The return type of the input() function is 1 SQP 2022
a. string b. integer c. list d. tuple
11 Which of the following components are part of a function header in Python? 1 SQP 2022
i. function name
ii. return statement
iii. parameter list
iv. def keyword
a. only I b. i and iii c. iii and iv d. iiii and iv
12 For a function header as follows : 1 2022 Term 1
def Calc(X, Y=20) :
Which of the following function calls will give an Error ?
(a) Calc(15,25) (b) Calc(X=15,Y=25)
(c) Calc(Y=25) (d) Calc(X=25)
13 Which of the following function headers is correct? 1 SQP 2022
a. def cal_si(p = 100, r, t = 2):
b. def cal_si(p = 100, r = 8, t):
c. def cal_si(p, r = 8, t):
d. def cal_si(p, r = 8, t = 2):
14 Which of the following is the correct way to call a function? 1 SQP 2022
a. my_func() b. def my_func()
c. return my_func d. call my_func()
15 Differentiate between actual parameter(s) and a formal parameter(s) with a suitable 2 SQP 2021
example for each.
16 Explain the use of global key word used in a function with the help of a suitable 2 SQP 2021
example.
17 What do you understand by local and global scope of variables? How can you access a 2 SQP 2019
global variable inside the function, if function has a variable with same name.
18 What will be the output of the following Python code? 1 SQP 2022
def add (num1, num2):
sum = num1 + num2
sum = add(20,30)
print(sum)

a. 50 b. 0 c. Null d. None
19 What will be the output of the following code? 1 SQP 2022
def my_func(var1=100, var2=200):
var1+=10
var2 = var2 - 10
return var1+var2
print(my_func(50),my_func())

a. 100 200 b. 150 300 c. 250 75 d. 250 300


20 What will be the output of the following code? 1 SQP 2022
value = 50
def display(N):
global value
value = 25
if N%7==0:
value = value + N
else:
value = value - N
print(value, end="#")
display(20)
print(value)

a. 50#50 b. 50#5 c. 50#30 d. 5#50#


21 What is the output of the following code snippet? 1 SQP 2022
def ChangeVal(M,N): Comptt 2020
for i in range(N): – Old & New
if M[i]%5 == 0:
M[i]//=5
if M[i]%3 == 0:
M[i]//=3
L = [25,8,75,12]
ChangeVal(L,4)
for i in L:
print(i,end="#")
a) 5#8#15#4# b) 5#8#5#4# c) 5#8#15#14# d) 5#18#15#4#
22 Find and write the output of the following python code: 3 Comptt 2020
def Change(P, Q=30): – Old & New
P=P+Q
Q=P-Q
print( P,"#",Q)
return (P)
R=150
S=100
R=Change(R,S)
print(R,"#",S)
S=Change(S)
23 What will be the output of the following code? 1 SQP 2022
x = 3
def myfunc():
global x
x+=2
print(x, end=' ')
print(x, end=' ')
myfunc()
print(x, end=' ')

a. 3 3 3 b. 3 5 3 c. 3 3 5 d. 3 5 5
24 Find and write the output of the following python code: 1 SQP 2019
a=10
def call():
global a
a=15
b=20
print(a)
call()
25 Find and write the output of the following Python code: 3 Comptt 2020
def Assign(P=30,Q=40): - Old
P=P+Q
Q=P–Q
print(P,'@',Q)
return P
A=100
B=150
A=Assign(A,B)
print(A,'@',B)
B=Assign(B)
print(A,'@',B)
26 Write the output of the following Python code : 1 Comptt 2020
def Update(X=10): - New
X += 15
print('X = ', X)
X=20
Update()
print('X = ', X)
27 35. Identify the correct possible output for the following Python code : 1 2022 term 1
import random
for N in range(2,5,2) :
print(random.randrange(1,N),end="#")

(a) 1#3#5# (b) 2#3# (c) 1#4# (d) 1#3#


28 Which of the following options can be the output for the following code? 2 SQP 2022
import random
List=["Delhi","Mumbai","Chennai","Kolkata"]
for y in range(4):
x = random.randint(1,3)
print(List[x],end="#")

a. Delhi#Mumbai#Chennai#Kolkata#
b. Mumbai#Chennai#Kolkata#Mumbai#
c. Mumbai# Mumbai #Mumbai # Delhi#
d. Mumbai# Mumbai #Chennai # Mumbai
29 What possible outputs(s) are expected to be displayed on screen at the time of execution 2 SQP 2021
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#


30 What possible outputs(s) are expected to be displayed on screen at the time of execution 2 SQP 2019
of the program from the following code? Also specify the maximum values that can be
assigned to each of the variables FROM and TO.
import random
AR = [20,30,40,50,60,70];
FROM = random.randint(1, 3)
TO = random.randint(2, 4)
for K in range(FROM, TO+1):
print (AR[K], end = ”#“)

(i) 10#40#70# (ii) 30#40#50# (iii) 50#60#70# (iv) 40#50#70#


31 What possible output(s) are expected to be displayed on screen at the time of 2 Comptt 2020
execution of the program from the following code ? Also, specify the minimum and – Old & New
maximum values that can be assigned to the variable End.
import random
Rainbow = ["VIOLET","INDIGO","BLUE","GREEN",
"YELLOW","ORANGE","RED"]
End = randrange(2)+3
Begin = randrange(End)+1
for i in range (Begin,End):
print( Rainbow[i],end="&")
(i) INDIGO&BLUE&GREEN& (ii) VIOLET&INDIGO&BLUE&
(iii) BLUE&GREEN&YELLOW& (iv) GREEN&YELLOW&ORANGE&
32 What possible output(s) are expected to be displayed on screen at the time of xecution 2 Comptt 2019
of the program from the following Python code ? Also specify the minimum values that - Old
can be assigned to each of the variables BEGIN and LAST.
import random
VAL=[80,70,60,50,40,30,20,10]
Start=random.randint(1,3)
End=random.randint(Start,4)
for I in range(Start,End+1):
print(VAL[I],end="*")
(i) 40*30*20*10* (ii) 70*60*50*40*30*
(iii) 50*40*30* (iv) 60*50*40*30*
33 What possible output(s) are expected to be displayed on screen at the time of execution 2 2019 - Old
of the program from the following code ? Also specify the minimum values that can be
assigned to each of the variables BEGIN and LAST.
import random
VALUES=[10,20,30,40,50,60,70,80]
BEGIN=random.randint(1,3)
LAST=random.randint(BEGIN,4)
for I in range(BEGIN,LAST+1):
print(VALUES[I],end="-")

(i) 30-40-50- (ii) 10-20-30-40-


(iii) 30-40-50-60- (iv) 30-40-50-60-70-
34 What will be the output of the following Python code ? 1 2022 Term 1
S="WELCOME"
def Change(T):
T="HELLO"
print(T, end='@')
Change(S)
print(S)
(a) WELCOME@HELLO (b) HELLO@HELLO
(c) HELLO@WELCOME (d) WELCOME@WELCOME
35 Find and write the output of the following Python code: 2 SQP 2021
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('Fun@Python3.0')
36 Find and write the output of the following python code: 2 SQP 2019
def fun(s):
k=len(s)
m=" "
for i in range(0,k):
if(s[i].isupper()):
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
else:
m=m+'bb'
print(m)
fun('school2@com')
37 Find and write the output of the following python code : 2 2019 - Old
Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+"*"
print Msg3
38 What will be the output of the following Python code ? 1 2022 term 1
def FunStr(S) :
T = ""
for i in S:
if i.isdigit() :
T = T + i
return T
X = "PYTHON 3.9"
Y = FunStr(X)
print(X, Y, sep="*")
(a) PYTHON 3.9 (b) PYTHON 3.9*3.9
(c) PYTHON 3.9*39 (d) Error
39 What will be the output of the following Python code ? 1 2022 term 1
v = 50
def Change(N):
global V
V, N = N, V
print(V, N, sep="#",end="@")
Change(20)
print(V)
(a) 20#50@20 (b) 50@20#50 (c) 50#50#50 (d) 20@50#20
40 What is the output of the following Python code ? 1 2022 term 1
def ListChange():
for i in range(len(L)):
if L[i]%2 == 0:
L[i]=L[i]*2
if L[i]%3 == 0:
L[i]=L[i]*3
else :
L[i]=L[i]*5
L = [2,6,9,10]
ListChange()
for i in L:
print(i,end="#")
(a) 4#12#27#20# (b) 6#18#27#50#
(c) 20#36#27#100# (d) Error
41 What will be the output of the following Python code ? 1 2022 term 1
V = 25
def Fun(Ch):
V=50
print(V, end=Ch)
V *= 2
print(V, end=Ch)
print(V, end="*")
Fun("!")
print(V)
(a) 25*50!100!25 (b) 50*100!100!100
(c) 25*50!100!100 (d) Error
42 Find and write the output of the following Python code : 3 Comptt 2019
def Alter(P=15,Q=10): - Old
P=P*Q
Q=P/Q
print(P,"#",Q)
return Q
A=100
B=200
A=Alter(A,B)
print(A,"$",B)
B=Alter(B)
print(A,"$",B)
A=Alter(A)
print(A,"$",B)
43 Find and write the output of the following python code : 3 2019 - Old
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)
B=Changer(B)
print(A,"$",B)
A=Changer(A)
print(A,"$",B)
45 Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers and n is 3 SQP 2021
a numeric value by which all elements of the list are shifted to left.
Sample Input Data of the list
Arr = [ 10,20,30,40,12,11], n=2
Output
Arr = [30,40,12,11,10,20]
46 Write a Recursive function in python BinarySearch(Arr,l,R,X) to search the 3 SQP 2019
given element X to be searched from the List Arr having R elements,where l represents
lower bound and R represents the upper bound.
47 Write a Recursive function factorial(n) in python to calculate and return the 3 SQP 2019
factorial of number n passed to the parameter.
48 Write the definition of a function AddPrev(A, N) in Python, which should add every 3 Comptt 2020
previous value of list A to the next value and assign the sum at the index of the next - Old
value. The list A contains N number of integers. The function should finally display the
entire content of the changed list.
Example: If the list A contains the following 10 elements (i.e. for N=10).
0 1 2 3 4 5 6 7 8 9
9 5 15 10 25 12 5 9 5 12
Then the function should display the output as follows:
9 # 14 # 29 # 39 # 64 # 76 # 81 # 90 # 95 # 107 #
49 Write the definition of a function ChangeEvenOdd(Num, N) in Python, which 3 Comptt 2020
should add 1 to every even number and subtract 1 from every odd number. The function Old
should finally display the changed content of the list Num.
Example: If the list Num contains the following 10 elements (i.e. for N=10)
0 1 2 3 4 5 6 7 8 9
25 12 5 10 9 5 15 9 5 12
Then the function should display the output as follows :
24 13 4 11 8 4 14 8 4 13

50 Write a Python method/function SwapParts(Word) to swap the first part and the second 2 Comptt 2020
part of the string Word. Assuming there are an even number of letters in the string - Old
Word. The function should finally display the changed Word.
For example: If Word = 'Elephant’ then the function should convert Word to
'hantElep'
and display the output as:
Changed Word is hantElep
51 Write a Python method/function Noun2Adj(Word) which checks if the string Word 2 Comptt 2020
ends with the letter ‘y’. If so, it replaces the last letter ‘y’ with the string ‘iful’ and - Old
then displays the changed Word.
For example, if the Word is "Beauty", then the Word should be changed to
"Beautiful".
Otherwise it should display
Not ending with "y"

52 Write a Recursive function in Python RecsumNat(N), to return the sum of the first 3 Comptt 2020
N natural numbers. For example, - New
if N is 10 then the function should return (1 + 2 + 3 + ... + 10 = 55).
53 Write a Recursive function in Python Power(X,N), to return the result of X raised to 3 Comptt 2020
the power N where X and N are non-negative integers. - New
For example, if X is 5 and N is 3 then the function should return the result of
(5)3 i.e. 125.
54 Write definition of a method/function DoubletheOdd(Nums) to add and display 2 Comptt 2019
twice of odd values from the list of Nums. For example : - Old
If the Nums contains [25,24,35,20,32,41]
The function should display
Twice of Odd Sum: 202
55 Write definition of a method/function FindOut(Names, HisName) to search for 2 Comptt 2019
HisName string from a list Names, and display the position of its presence. - Old
For example: If the Names contain ["Arun","Raj","Tarun","Kanika"]
and HisName contains "Tarun"
The function should display
Tarun at 2
56 Write a Python method/function SwitchOver(Val) to swap the even and odd 2 Comptt 2019
positions of the values in the list Val. - Old
Note : Assuming that the list has even number of values in it. For example :
If the list Numbers contain
[25,17,19,13,12,15]
After swapping the list content should be displayed as
[17,25,13,19,15,12]
57 Write a Python method/function Count(Start,End,Step) to display natural 2 Comptt 2019
numbers from Start to End in equal intervals of Step. For example : - Old
If the values of Start as 14, End as 35 and Step as 6
The method should be displayed as
14
20
26
32
58 Write definition of a method/function AddOddEven(VALUES) to display sum of odd 3 2019 - Old
and even values separately from the list of VALUES.
For example : If the VALUES contain [15, 26, 37, 10, 22, 13]
The function should display
Even Sum: 58
Odd Sum: 65
59 Write definition of a method/function HowMany(ID,Val) to count and display 3 2019 - Old
number of times the value of Val is present in the list ID. 3
For example : If the ID contains [115,122,137,110,122,113]
and Val contains 122
The function should display
122 found 2 Times
60 Write a python method/function Swapper(Numbers) to swap the first half of the 2 2019 - Old
content of a list Numbers with second half of the content of list Numbers and display
the swapped values.
Note : Assuming that the list has even number of values in it.
For example : If the list Numbers contains [35,67,89,23,12,45]
After swapping the list content should be displayed as
[23,12,45,35,67,89]
61 Write a python method/function Count3and7(N) to find and display the count of all 2 2019 - Old
those numbers which are between 1 and N, which are either divisible by 3 or by 7.
For example : If the value of N is 15
The sum should be displayed as
7
(as 3,6,7,9,12,14,15 in between 1 to 15 are either divisible by 3 or 7)

You might also like