0% found this document useful (0 votes)
134 views13 pages

Revision Tour I - II - Question Bank

The document provides a comprehensive overview of Python programming concepts, including tokens, keywords, identifiers, literals, operators, and data types. It also covers dynamic typing, type casting, mutable and immutable data types, along with a question bank for revision. The questions test knowledge on Python syntax, operations, and data structures.

Uploaded by

amuthavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views13 pages

Revision Tour I - II - Question Bank

The document provides a comprehensive overview of Python programming concepts, including tokens, keywords, identifiers, literals, operators, and data types. It also covers dynamic typing, type casting, mutable and immutable data types, along with a question bank for revision. The questions test knowledge on Python syntax, operations, and data structures.

Uploaded by

amuthavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

PEARLS PUBLIC SCHOOL (CBSE)

REVISION TOUR – I & II


1. The smallest individual unit in a python program is known as Token or Lexical Unit
2. A token has a specific meaning for a python interpreter
3. Examples of tokens are: Keywords, Identifiers, Literals, Operators and Punctuators
4. Keywords are the reserved words and have special meaning for Python Interpreters
5. Each keyword can be used only for that purpose which it has been assigned

Python
Keyword
s

6. Identifiers are the names given to variables, objects, classes or functions etc. there are some predefined
rules for forming identifiers which should be followed else the program will raise Syntax Error
7. The data items that have a fixed value are called Literals
8. If a data item holds numeric values it will be known as Numeric Literal
9. If it contains String values it will be known as String Literal and so on.
10. It means the type of value stored by the data item will decide the type of Literal.
11. Python has one special literal which is None to indicate absence of value.
12. Operators are the symbols that perform specific operations on some variables
13. Punctuators are the symbols that are used to organize sentence structure in programming languages.
14. Common punctuators are ‘ ‘’ # $ @ *+ ,- = ; () ,
15. Variables are not storage containers like other programming languages
16. Variables are the temporary memory locations used to store values which will be used in the program further
17. In Python we do not specify the size and type of variable, besides these are decided as per the value we assign
to that variable (In Python data type declaration is implicit)
18. Data Type specifies the type of data we will store in the variable according to which memory will be allocated
to that variable and it will also specify the type of operations that can be performed on that variable.
Examples: integer, string, float, list etc
19. Dynamic Typing - implicit conversion
20. Type Casting - data type conversion of a variable is done explicitly by using some built-in functions (int(),
float(), str(), list(), tuple(), dict())
21. Mutable data types are those data types whose value can be changed without creating a new object
22. Immutable data types are those data types whose value cannot be changed after they are created

QUESTION BANK
Section - A
What will be the output of the following python statement?
L=[3,6,9,12]
1.
L=L+15
print(L)
Identify the output of the following python statements
import random
2. for n in range(2,5,2):
print(random.randrange(1,n,end=’*’)
(a)1*3 (b) 2*3 (c) 1*3*4 (d)1*4
Which of the following is an invalid identifier?
3.
(a)_123 (b) E_e12 (c) None (d) true
Consider the given expression:
7%5==2 and 4%2>0 or 15//2==7.5
4.
Which of the following will be correct output if the given expression is evaluated?
(a)True (b) False (c)None (d)Null
What will be the output of the code:
s = "Question paper 2022-23"
5.
s= s.split('2')
print(s)
What will be the output of the following python code:
D=,1:”one”,2:”two”, 3:”three”-
L=[]
6. for k,v in D.items():
if ‘o’ in v:
L.append(k)
print(L)
Which of the following is not a tuple in python?
7.
(a) (10,20) (b) (10,) (c) (10) (d) All are tuples.
l1 = [1,2,3,4,5]
8. l1.append([5,6,[7,8,[9,10])
What will be the final length of l1?
9. State true or false: Like while, the for loop also works with conditions and truth values.
10. If L1 = [1, 3, 5] and L2 = [2, 4, 6] then L1 + L2 will yield
11. State true or false: A dictionary can contain keys of any valid Python types
S="Amrit Mahotsav @ 75"
12. A=S.split(" ",2)
print(A)
dry = {0: 'a', 1: 'b', 2: 'c'}
13. for x, y in dry. items():
print(x, y, end = ' ')
Which of the following operator cannot be used with string data type?
14.
a) * b) in c) / d) +
Which of the following will delete key:value pair for key="tiger" in dictionary?
15. di = {"lion":"wild","tiger":"wild", "cat": "domestic","dog":"domestic"}
a) del di["tiger"] b) del(di.["tiger"]) c) delete(di.["tiger"]) d) di["tiger"].delete()
16. State true or false: The keys of a dictionary must be of immutable types.
What will be the result of the following code?
17. dl={"abc":5, "def":6, "ghi":7}
print(dl[0])
18. State True or False "In Python, data type of a variable depends on its value"
19. What will be the output of the following python expression? print(2**3**2)
What will be the output of the following python dictionary operation?
20. data = {'A':2000, 'B':2500, 'C':3000, 'A':4000}
print(data)
Choose the most correct statement among the following
a. a dictionary is a sequential set of elements
21. b. a dictionary is a set of key-value pairs
c. a dictionary is a sequential collection of elements key-value pairs
d. a dictionary is a non-sequential collection of elements
22. a = "Year 2024 at all the best"
a = a.split('a')
b = a[0] + "-" + a[1] + "-" + a[3]
print (b)
Which of the following statement(s) would give an error during execution?
S=["CBSE"] # Statement 1
S+="Delhi" # Statement 2
23.
S[0]= '@' # Statement 3
S=S+"Thank you" # Statement 4
a) Statement 1 b) Statement 2 c) Statement 3 d) Statement 4
Give the output:
dic1=,‘r’:’red’,’g’:’green’,’b’:’blue’-
24.
for i in dic1:
print (i,end=’’)
Select the correct output of the code:
25. for i in "QUITE":
print([i.lower()], end= "#")
Choose the best option for the possible output of the following code
import random
26. L1=[random.randint(0,10) for x in range(3)]
print(L1)
(a) [0,0,7] (b) [9,1,7] (c) [10,10,10] (d) All are possible
Predict the correct output of the following Python statement
27.
7%5==2 and 4%2>0 or 15//2==7.5
Predict the output of the following code.
28. data=[ ‘Python’ ,’Language’ ]
print( ‘#’ .join(data))
Consider the string state = BHUBANESHWAR . Identify the appropriate statement that will display the last
29. five characters of the string state?
(a) state [-5:] (b) state [4:] (c) state [:4] (d) state [:-4]
30. What will be the data type of d, if d = (15,) ?
Identify the output of the following python statements .
import random
31. for n in range(2,5,2):
print(random.randrange(1,n), end=’*’)
(a)1*3* (b) 2*3* (c) 1*3*4* (d)1*4*
Which of the following is an invalid identifier to be used in Python?
32.
a. __if__ b. rate/kg c. Not d. false
What will be the output of :
33. print( "Hey Prabhu , Jagganath , What has happened"[4:11]+"Hey Prabhu , Jagganath , What has
happened"[-7:-4] )
Which of the following statement(s) would give an error during the execution of the following code?
emoji = {'rank':34 , 'rgb':(23,67,34) , 'emotion':'sad' , 'sizes':["10px","20px","30"]}
(I) emoji['rank'] = '56'
34. (II) emoji['sizes'][-1]=emoji['sizes'][-1].replace("30","30px")
(III) emoji['rgb'][1]+=10
(IV) emoji['emotion'][0]='d'
a. ( I ) b. (II) c. ( III ) d. ( III ) & ( IV )
What will be the output of the following code?
35. s = [3,0,[2,1,2,3],1]
print(s[s[len(s[2])-2][1]])
36. State True or False “Lists support two-way indexing.”
Which of the following is the valid variable name?
37.
(a) _ d t (b) 2xy (c) for (d) Is
What will be the output of following code
38. d = {1:'One',2:'Two',3:'Three',4:'Four'}
print(list(d.keys()))
If x=10,y=20,z=30 then output of following python statement will be
39.
print(z-y/x+int(x/z))
What will be the output of the following code :
40. word=“Pre Board”
print(word.split(‘-’))
Find output generated by the following code:
41. txt = "fun with python"
print(txt.find("th",7,14))
42. State True or False : “Keywords can be used as identifiers in Python.”
What will be the output of the following statement :
43.
print( 3 – 2 ** 2 ** 2 + 77 / 11 )
What will be the output of the code :
s = ‘question paper cs’
44.
s =s[0].upper() + s[1 : : -1] + s[-1].upper() + s[0]
print(s)
Which of the following statement(s) would give an error during execution?
S = ["CBSE"] # Statement 1
45. S += "Delhi" # Statement 2
S[0] = '@' # Statement 3
S = S + "Thank you" # Statement 4
What will be the output of this code :
46. >>>L1 =[8, 11,20]
>>>L1*3
Write the output from the following code :
47. s = 'WorldCup2023'
print('C' in s)
Write the output of the following Python code :
48. for i in range (5, 20, 5):
print ( i + '-' )
Write a statement in Python to declare a dictionary day whose keys are 1, 2, 3 and values are Monday,
49.
Tuesday and Wednesday respectively
50. What will be the output of the statement : (not True) and False or True
Predict the correct output of the following Python statement –
51.
print(4 + 3**3/2)
Consider the string state = “Guwahati”. Identify the appropriate statement that will display the last five
52. characters of the string state?
(a) state [-5:] (b) state [4:] (c) state [:4] (d) state [:-4]
What will be the output of the code:
s = "Question paper 2023-24"
53.
s= s.split('2')
print(s)
Find the output of the given Python program?
>>>t = (1)
54.
>>>type(t)
a) <class ‘int’> b) <class ‘float’> c) <class ‘list’> d) <class ‘tuple’>
Consider the code given below:

55.
Which of the following statements should be given in the blank for #Missing Statement, if the output
produced is 110?
a. global a b. global b=100 c. global b d. global a=100
56. State True or False “If a loop terminates using break statement, loop else will not execute”
What will be the output of the following code snippet?
a=10
b=20
57. c=-5
a,b,a = a+c,b-c,b+c
print(a,b,c)
a) 5 25 -5 b) 5 25 25 c) 15 25 -5 d) 5 25 15
What is the result of the following code in python?
58. S="ComputerExam"
print(S[2]+S[-4]+S[1:-7])
Consider a list L = [5, 10, 15, 20], which of the following will result in an error.
59.
a) L[0] += 3 b) L += 3 c) L *= 3 d) L[1] = 45
Which of the following is not true about dictionary?
60. a) More than one key is not allowed b) Keys must be immutable
c) Values must be immutable d) When duplicate keys encountered, the last assignment wins
Which of the following statements 1 to 4 will give the same output?
tup = (1,2,3,4,5)
print(tup[:-1]) #Statement 1
61.
print(tup[0:5]) #Statement 2
print(tup[0:4]) #Statement 3
print(tup[-4:]) #Statement 4
What possible outputs(s) will be obtained when the following code is
executed?
import random
VALUES = [10, 20, 30, 40, 50, 60, 70, 80]
62. BEGIN = random.randint(1,3)
LAST = random.randint(BEGIN, 4)
for x in range(BEGIN, LAST+1):
print(VALUES[x], end = "-")
a) 30-40-50- b) 10-20-30-40- c) 30-40-50-60- d) 30-40-50-60-70-
Predict the output of the following code:
def ChangeLists(M , N):
M[0] = 100
N = [2, 3]
63.
L1 = [-1, -2]
L2 = [10, 20]
ChangeLists(L1, L2)
print(L1[0],"#", L2[0]
64. State True or False: “The else clause of python loop executes when the loop terminates normally”
65. What is the output of the following expression? print( float(5+int(4.39+2.1)%2))
What will be the output of the python code:
X="Swatchtha Hi Seva @ Swatcch Bharat"
66.
Y=X.split()
print(Y)
Given the following dictionaries
dict_fruit={"Banana":"Yellow", "DraganFruit":"Pink"}
dict_vegetable={"Chilli":"Green", "Brinjal":"Purple"}
67.
Which statement will merge the contents of both dictionaries?
a) dict_fruit.update(dict_vegetable) b) dict_fruit + dict_vegetable
c) dict_fruit.add(dict_vegetable) d)dict_fruit.merge(dict_vegetable)
Which of the following statement(s) would give an error after executing the following code?
Str="BharatiyaBashaUtsav" # Statement 1
print(Str) # Statement 2
68.
Str="India @ 75" # Statement 3
Str[1]= '$' # Statement 4
Str=Str+"Thank you" # Statement 5
Consider the statements given below and then choose the correct output from the given options:
tp1=(10,15,20,60)
69. tp1=tp1+(3)
print(tp1)
a. (10,15,20,60,3) b. (3,10,15,20,60) c. (10,15,20,60, (3)) d. Error
What could be the minimum possible and maximum possible numbers generated by following code?
70. import random
print(random.randint(3,10)-3)
Find and write the output of the following python code:
a=10
def call():
global a
71.
a=15
b=20
print(a)
call()
State True or False: A string can be surrounded by three sets of single quotation marks or by three sets
72.
of double quotation marks.
Which of the following is not a Tuple in Python?
73.
(a) (1, 2, 3) (b) (“One”, “Two”, “Three”) (c) (10, ) (d) (“One”)
Which of the following will delete key-value pair for key = “Red” from a dictionary D1?
74.
a. delete D1("Red") b. del D1["Red"] c. del.D1["Red"] d. D1.del["Red"]
What will be the output of the following code snippet?
Lst = [1,2,3,4,5,6,7,8,9]
Lst[ : : 2]=10,20,30,40,50,60
75. print(Lst)
(a) ValueError : attempt to assign sequence of size 6 to extended slice of size 5
(b) [10, 2, 20, 4, 30, 6, 40, 8, 50, 60] (c) [1, 2, 10, 20, 30, 40, 50, 60]
(d) [1, 10, 3, 20, 5, 30, 7, 40, 9, 50, 60]
Section - B
Rewrite the following code in python after removing all syntax error(s). Underline each correction done in
the code.
30=Value
for VAL in range(0,Value)
If val%4==0:
1.
print (VAL*4)
Elseif val%5==0:
print (VAL+3)
else
print(VAL+10)
s=”Up Above The World So High”
2.
Write the output of: print(s[::-4])
Write the output of the code given below:
D=,‘month’:’DECEMBER’,’exam’:’PREBOARD1’-
3. D*‘month’+=’JANUARY’
D*‘EXAM’+=’PRE2’
print(D.items())
Predict the output of the Python code given below: 2
L=[4,6,7,1,6,9,4]
def fun(L):
for i in range(len(L)):
if(L[i]%3==0 and L[i]%2==0):
4. L[i]=L[i]+1
print(L)
return(L)
print(L)
k=fun()
print(k)
Predict the output of the Python code given below:
T = (9,18,27,36,45,54)
L=list(T)
L1 = []
5. for i in L:
if i%6==0:
L1.append(i)
T1 = tuple(L1)
print(T1)
What will be the output of the following code snippet?
dc1 = { }
dc1[1] = 1
dc1['1'] = 2
6. dc1[1.0] = 4
sum = 0
for k in dc1:
sum += dc1[k]
print (sum)
Observe the following tuples and answer the questions that follow.
t1= (4, 7, 8, 9)
t2=(0, 4, 3)
7.
t=t1+t2
print(t)
t=t1*t2
print(t)
What will be the output of the following code snippet?
my_dict = {}
my_dict[(1,2,4)] = 8
my_dict[(4,2,1)] =10
my_dict[(1,2)]=12
8.
sum = 0
for k in my_dict:
sum += my_dict[k]
print (sum)
print(my_dict)
Predict the output of following code fragment:
fruit = { }
f1 = ['Apple', 'Banana', 'apple', 'Banana']
for index in f1:
if index in fruit:
9.
fruit [index] += 1
else:
fruit[index] =1
print(fruit)
print (len(fruit))
Predict the output of the following code:
value = 50
def display(N):
global value
value = 25
if N%7==0:
10.
value = value + N
else:
value = value - N
print(value, end="#")
display(20)
print(value)
Predict the output of the Python code given below:
a=20
def call():
global a
b=20
11.
a=a+b
return a
print(a)
call()
print(a)
12. Predict the output of the Python code given below:
Find error in the following code(if any) and correct code by rewriting code and underline the correction;
x= int( Enter value of x: )
for in range [0,10]:
13. if x=y
print( x + y)
else:
print( x y)
Find output generated by the following code:
L1=[10,15,20,25]
L2=[]
14.
for i in range(len(L1)):
L2.insert(i,L1.pop())
print(L1,L2,sep= & )
Write the Python statement for each of the following tasks using BUILT-IN functions/methods only.
15. (i) To sort the contents of a list Lst in reverse order.
(ii) To check if string named S1, contains only alphabets or not.
What is the output of the following python code.
L=[2,6,9,10]
def ListChange():
for i in range(len(L)):
if L[i]%2==0:
L[i]=L[i]*2
16. elif L[i]%3==0:
L[i]=L[i]*3
else:
L[i]=L[i]*5
ListChange()
for i in L:
print(i,end= # )
Predict the output of the code given below.
def Convert(old):
l=len(old)
new= ‘’
for i in range(0,l):
if old[i].isupper():
new=new+old[i].lower()
17.
elif old[i].islower():
new=new+old[i].upper()
elif old[i].isdigit():
new=new+ *
else:
new=new+ %
return new
older= ‘InDia@2020’
newer=Convert(older)
print( ‘Newer String is’ ,newer)
Sunita has written certain code to work with tuples. He is getting some errors. Find the errors:
t1= (10,20, 30, 40,50, 60, 70, 80)
t2=(90,100,110, 120)
18.
t3=t1*t2
Print (t5 [0:12:3])
t1[2]=100
What will be the output of the following code?
Data = ["P", 20, "R", 10, "S", 30]
Times = 0
Alpha = ""
Add = 0
19.
for C in range (1, 6, 2) :
Times = Times + C
Alpha = Alpha + Data [C-1]+"$"
Add = Add + Data [C]
print (Times, Add, Alpha)
Write the Python statement for each of the following tasks using BUILT- IN functions/methods only:
20. (a) To display only the last two keys of the dictionary named D
(b) To display the elements of the list Lst from index -10 to -4 in reverse order.
Write the output of the following code snippet:
tup = ('cold',)
n=4
for i in range(int(n)):
if i % 2 == 0:
21. tup = (tup,'cold')
else:
if i > 1:
continue
tup = (tup , 'hot')
print(tup)
Find error in the following code(if any) and correct code by rewriting code and underline the correction;‐
s = [11, 13, 15]
22. for n in len(s):
tot = tot + s(n)
print(tot)
Find output generated by the following code:
text = 'ABCD'
number = '1357'
i=0
23. s =''
while i < len(text):
s = s + text[i] + number[len(number)-i-1]
i=i+1
print(s)
Predict the output of the Python code given below:
List1 = list("Examination")
List2 =List1[1 : -1]
24. new_list = []
for i in List2:
j=List2.index(i)
if j%2==0:
List1.remove(i)
print(List1)
Mithilesh has written a code to input a number and evaluate its factorial and then finally print the result in
the format : “The factorial of the <number> is <factorial value>” His code is having errors. Rewrite the
correct code and underline the corrections made.
f=0
num = input("Enter a number whose factorial you want to evaluate :")
25. n = num
while num > 1:
f = f * num
num -= 1
else:
print("The factorial of : ", n , "is" , f)
Write the output of the code given below:
data = [2,4,2,1,2,1,3,3,4,4]
d = {}
for x in data:
26. if x in d:
d[x]=d[x]+1
else:
d[x]=1
print(d)
Predict the output based on the list, cod = [98, 45, 62, 14, 1007]
27.
a) print(cod * 2) b) print(cod[:2]+cod[2:]) c) print(cod. pop(1)) d) print(cod.pop())
(a) Given is a Python List declaration:
lst1= [39, 45, 23, 15, 25, 60].
What will be the output of : print(lst1.index(23))
(b) Write the output of the code given below:
28.
x = *“rahul”, 5, “B”, 20, 30+
x.insert(1,3)
x.insert( 3, “akon”)
print(x[2])
Write the output of the following code:
def change(m, n=10):
global x
x+=m
n+=x
29.
m=n+x
print(m,n,x)
x=20
change(10)
change(20)
Predict the output of the Python code given below:
myvalue = ["A", 40, "B", 60, "C", 20]
alpha = 0
beta = ""
gama = 0
30.
for i in range(1,6,2):
alpha += i
beta += myvalue[i-1]+ "#"
gama += myvalue[i]
print(alpha, beta, gama)
Rewrite the following code in python after removing all syntax error(s) and underline each
31.
correction made by you in the code.
D = dict[]
c=1
while c < 5:
k = input(“Name: “)
v = int(input(“Age: “)
D(k) = v
print(popitem())
for a,b in D.item:
print(a, b)
Write the output of the following code:
L1=[100,900,300,400,500]
START=1
SUM=0
32. for C in range (START, 4):
SUM=SUM+L1[C]
print(C,":",SUM)
SUM=SUM+L1[0]*10
print(SUM)
(a) Given is a Python string declaration:
st = ‘AMPLIFY&AMPLITUTE’
Write the output of : print(st.count(‘PLI’,2,12))
33.
(b) Write the output of the code given below:
D = ,‘A’:’AJAY’ , ‘GRADE’:’A’-
print(list(D.values()))
Predict the output of the Python code given below:
x = 25
def modify(s, c=2):
global x
for a in s:
if a in 'QWEiop':
x //= 5
34.
print(a.upper(),'@',c*x)
else:
x += 5
print(a.lower(),'#',c+x)
string = 'We'
modify(string,10)
print(x, '$', string)
Predict the output of the Python code given below:
L=[4,3,6,8,2]
Lst=[]
for i in range(len(L)):
35.
if L[i]%2==0:
t=(L[i],L[i]**2)
Lst.append(t)
print(Lst)
Predict the output of the following code:
def ChangeVal(M,N):
for i in range(N):
if M[i]%5==0:
36. M[i]+=5
if M[i]%3==0:
M[i]+=3
L=[5,8,15,12]
ChangeVal(L,4)
for i in L:
print(i,end='$')
Predict the output of the following code:
L1=[10,20,30,40,12,11]
n=2
l=len(L1)
for i in range (0,n):
37.
y=L1[0]
for j in range(0,l-1):
L1[j]=L1[j+1]
L1[l-1]=y
print(L1)
Predict the output of the Python code given below:
tuple1 = (11, 22, 33, 44, 55, 66)
list1 =list(tuple1)
new_list = [ ]
38. for i in list1:
if i%2 == 0:
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)
Predict the output of the following code:

39.

Find and write the output of the following python code:


def Change(P ,Q=30):
P=P+Q
Q=P-Q
print( P,"#",Q)
40. return (P)
R=150
S=100
R=Change(R,S)
print(R,"#",S)
S=Change(S)

You might also like