50% found this document useful (6 votes)
9K views

Chapter-1&2 Python Revision Tour I&II PDF

This document contains a question bank with multiple choice questions related to Python programming concepts covered in Chapters 1 and 2, including questions on Python identifiers, operators, data types, strings, lists, loops, and decision making statements. There are 61 total multiple choice questions testing knowledge of Python syntax, built-in functions, operations on various data types like strings and lists, and control flow structures.

Uploaded by

Joker 1N
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
50% found this document useful (6 votes)
9K views

Chapter-1&2 Python Revision Tour I&II PDF

This document contains a question bank with multiple choice questions related to Python programming concepts covered in Chapters 1 and 2, including questions on Python identifiers, operators, data types, strings, lists, loops, and decision making statements. There are 61 total multiple choice questions testing knowledge of Python syntax, built-in functions, operations on various data types like strings and lists, and control flow structures.

Uploaded by

Joker 1N
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/ 32

COMPUTER SCIENCE QUESTION BANK CLASS - XII

Chapter No.: 1, 2
Chapter Name: Python Revision Tour - I & II

Multiple Choice Questions: [1 mark]


1. Which of the following is a valid identifier:
i. 9type ii. _type iii. Same-type iv. True
2. Which of the following is a relational operator:
i. > ii. // iii. or iv. **
3. Which of the following is a logical operator:
i. + ii. /= iii. and iv. in
4. Identify the membership operator from the following:
i. in ii. not in iii. both i & ii iv. Only i
5. Which one is a arithmetic operator:
i. not ii. ** iii. both i & ii iv. Only ii
6. What will be the correct output of the statement : >>>4//3.0
i. 1 ii. 1.0 iii 1.3333 iv. None of the above
7. What will be the correct output of the statement:
>>> 4+2**2*10
i. 18 ii. 80 iii. 44 iv. None of the above
8. Give the output of the following code:
>>> a,b=4,2
>>> a+b**2*10
i. 44 ii. 48 iii. 40 iv. 88
9. Give the output of the following code:
>>> a,b = 4,2.5
>>> a-b//2**2
i. 4.0 ii. 4 iii. 0 iv. None of the above

1
COMPUTER SCIENCE QUESTION BANK CLASS - XII

10. Give the output of the following code:


>>>a,b,c=1,2,3
>>> a//b**c+a-c*a
i. -2 ii. -2.0 iii. 2.0 iv. None of the above
11. If a=1,b=2 and c= 3 then which statement will give the output
as: 2.0 from the following:
i. >>>a%b%c+1 ii. >>>a%b%c+1.0
iii. >>>a%b%c iv. a%b%c-1
12. Which statement will give the output as : True from the
following :
i. >>>not -5 ii. >>>not 5 iii. >>>not 0 iv. >>>not(5-1)
13. Give the output of the following code:
>>>7*(8/(5//2))
i. 28 ii. 28.0 iii. 20 iv. 60
14. Give the output of the following code:
>>>import math
>>> math.ceil(1.03)+math.floor(1.03)
i. 3 ii. -3.0 iii. 3.0 iv. None of the above
15. What will be the output of the following code:
>>>import math
>>>math.fabs(-5.03)
i. 5.0 ii. 5.03 iii. -5.03 iv . None of the above
16. Single line comments in python begin with………………..
symbol.
i. # ii. “ iii. % iv. _
17. Which of the following are the fundamental building block of a
python program.
i. Identifier ii. Constant iii. Punctuators iv. Tokens
18. The input() function always returns a value of ………..type.
i. Integer ii. float iii. string iv. Complex

2
COMPUTER SCIENCE QUESTION BANK CLASS - XII

19. ………. function is used to determine the data type of a variable.


i. type( ) ii. id( ) iii. print( ) iv. str( )
20. The smallest individual unit in a program is known as a………
i. Token ii. keyword iii. punctuator iv. Identifier
21. Which of the following is not a decision making statement
i. if..else statement ii. for statement
iii. if-elif statement iv. if statement
22. …………loop is the best choice when the number of iterations
are known.
i. while ii. do-while iii. for iv. None of these
23. How many times will the following code be executed.
a=5
while a>0:
print(a)
print(“Bye”)
i. 5 times ii. Once iii. Infinite iv. None of these
24. What abandons the current iteration of the loop
i. continue ii. stop iii. infinite iv. Break
25. Find the output of the following python program
for i in range(1,15,4):
print(i, end=’,’)
i. 1,20,3 ii. 2,3,4 iii. 1,5,10,14 iv. 1,5,9,13
26. …………loop is the best when the number of iterations are not
known.
i. while ii. do-while iii. for iv. None of these
27. In the nested loop ……………..loop must be terminated before
the outer loop.
i. Outer ii. enclosing iii. inner iv. None of these
28. …………..statement is an empty statement in python.
i. pass ii. break iii. continue iv. If

3
COMPUTER SCIENCE QUESTION BANK CLASS - XII

29. How many times will the following code be executed


for i in range(1,15,5):
print(i,end=’,’)
i. 3 ii. 4 iii. 1 iv. infinite
30. Symbol used to end the if statement:
i. Semicolon(;) ii. Hyphen(-) iii. Underscore( _ ) iv. colon(:)
31. Which of the following is not a python legal string operation.
i. ‘abc’+’aba’ ii. ‘abc’*3 iii. ‘abc’+3 iv. ‘abc’.lower()
32. Which of the following is not a valid string operation.
i. Slicing ii. concatenation iii. Repetition iv. floor
33. Which of the following is a mutable type.
i. string ii. tuple iii. int iv. list
34. What will be the output of the following code
str1=”I love Python”
strlen=len(str1)+5
print(strlen)
i. 18 ii. 19 iii. 13 iv. 15
35. Which method removes all the leading whitespaces from the left
of the string.
i. split() ii. remove() iii. lstrip() iv rstrip()
36. It returns True if the string contains only whitespace characters,
otherwise returns False.
i) isspace() ii. strip() iii. islower() iv. isupper()
37. It converts uppercase letter to lowercase and vice versa of the
given string.
i. lstrip() ii. swapcase() iii. istitle() iv. count()
38. What will be the output of the following code.
Str=’Hello World! Hello Hello’
Str.count(‘Hello’,12,25)
i. 2 ii. 3 iii. 4 iv. 5

4
COMPUTER SCIENCE QUESTION BANK CLASS - XII

39. What will be the output of the following code.


Str=”123456”
print(Str.isdigit())
i. True ii. False iii. None iv. Error
40. What will be the output of the following code.
Str=”python 38”
print(Str.isalnum())
i. True ii. False iii. None iv. Error
41. What will be the output of the following code.
Str=”pyThOn”
print(Str.swapcase())
i. PYtHoN ii. pyThon iii. python iv. PYTHON
42. What will be the output of the following code.
Str=”Computers”
print(Str.rstrip(“rs”))
i. Computer ii. Computers iii. Compute iv. compute
43. What will be the output of the following code.
Str=”This is Meera\’ pen”
print(Str.isdigit())
i. 21 ii. 20 iii. 18 iv. 19
44. How many times is the word ‘Python’ printed in the following
statement.
s = ”I love Python”
for ch in s[3:8]:
print(‘Python’)
i. 11 times ii. 8 times iii. 3 times iv. 5 times
45. Which of the following is the correct syntax of string slicing:
i. str_name[start:end] iii. str_name[start:step]
ii. str_name[step:end] iv. str_name[step:start]

5
COMPUTER SCIENCE QUESTION BANK CLASS - XII

46. What will be the output of the following code?


A=”Virtual Reality”
print(A.replace(‘Virtual’,’Augmented’))
i. Virtual Augmented iii. Reality Augmented
ii. Augmented Virtual iv. Augmented Reality
47. What will be the output of the following code?
print(“ComputerScience”.split(“er”,2))
i. [“Computer”,”Science”] iii. [“Comput”,”Science”]
ii. [“Comput”,”erScience”] iv. [“Comput”,”er”,”Science”]
48. Following set of commands are executed in shell, what will be
the output?
>>>str="hello"
>>>str[:2]
i. he ii. lo iii. olleh iv. hello
49. ………..function will always return tuple of 3 elements.
i. index() ii. split() iii. partition() iv. strip()
50. What is the correct python code to display the last four
characters of “Digital India”
i. str[-4:] ii. str[4:] iii. str[*str] iv. str[/4:]
51. Given the list L=[11,22,33,44,55], write the output of
print(L[: :-1]).
i. [1,2,3,4,5] ii. [22,33,44,55]
iii. [55,44,33,22,11] iv. Error in code
52. Which of the following can add an element at any index in the
list?
i. insert( ) ii. append( ) iii. extend() iv. all of these
53. Which of the following function will return a list containing all
the words of the given string?
i.split() ii. index() iii. count() iv. list()

6
COMPUTER SCIENCE QUESTION BANK CLASS - XII

54. Which of the following statements are True.


a. [1,2,3,4]>[4,5,6]
b. [1,2,3,4]<[1,5,2,3]
c. [1,2,3,4]>[1,2,0,3]
d. [1,2,3,4]<[1,2,3,2]
i. a,b,d ii. a,c,d iii. a,b,c iv. Only d
55. If l1=[20,30] l2=[20,30] l3=[‘20’,’30’] l4=[20.0,30.0] then
which of the following statements will not return ‘False’:
a. >>>l1==l2 b. >>>l4>l1 c. >>>l1>l2 d. >>> l2==l2
i. b, c ii. a,b,c iii. a,c,d iv. a,d
56. >>>l1=[10,20,30,40,50]
>>>l2=l1[1:4]
What will be the elements of list l2:
i. [10,30,50] ii. [20,30,40,50] iii. [10,20,30] iv. [20,30,40]
57. >>>l=[‘red’,’blue’]
>>>l = l + ‘yellow’
What will be the elements of list l:
i. [‘red’,’blue’,’yellow’] ii. [‘red’,’yellow’]
iii. [‘red’,’blue’,’yellow’] iv. Error
58. What will be the output of the following code:
>>>l=[1,2,3,4]
>>>m=[5,6,7,8]
>>>n=m+l
>>>print(n)
i. [1,2,3,5,6,7,8] ii. [1,2,3,4,5,6,7,8]
iii. [1,2,3,4][5,6,7,8] iv. Error

7
COMPUTER SCIENCE QUESTION BANK CLASS - XII

59. What will be the output of the following code:


>>>l=[1,2,3,4]
>>>m=l*2
>>>n=m*2
>>>print(n)
i [1,2,3,4,1,2,3,4,1,2,3,4] ii. [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4]
iii. [1,2,3,4][4,5,6,7] iv. [1,2,3,4]
60. Match the columns: if
>>>l=list(‘computer’)
Column A Column B
1. L[1:4] a. [‘t’,’e’,’r’]
2. L[3:] b. [‘o’,’m’,’p’]
3. L[-3:] c. [‘c’,’o’,’m’,’p’,’u’,’t’]
4. L[:-2] d. [‘p’,’u’,’t’,’e’,’r’]
i. 1-b,2-d,3-a,4-c iii. 1-c,2-b,3-a,4-d
ii. 1-b,2-d,3-c,4-a iv. 1-d,2-a,3-c,4-b
61. If a list is created as
>>>l=[1,2,3,’a’,[‘apple’,’green’],5,6,7,[‘red’,’orange’]]
then what will be the output of the following statements:
>>>l[4][1]
i. ‘apple’ ii. ‘red’ iii. ‘green’ iv. ‘orange’
62. >>>l[8][0][2]
i. ‘d’ ii. ‘r’ iii. ‘e’ iv. ‘o’
63. >>>l[-1]
i. [‘apple’,’green’] iii. [‘red’,’orange’]
ii. [‘red’ ] iv. [’orange’]
64. >>>len(l)
i. 10 ii. 8 iii. 9 iv. 11

8
COMPUTER SCIENCE QUESTION BANK CLASS - XII

65. What will be the output of the following code:


>>>l1=[1,2,3]
>>>l1.append([5,6])
>>>l1
i. [1,2,3,5,6] ii. [1,2,3,[5,6]] iii. [[5,6]] iv. [1,2,3,[5,6]]
66. What will be the output of the following code:
>>>l1=[1,2,3]
>>>l2=[5,6]
>>>l1.extend(l2)
>>>l1
i. [5,6,1,2,3] ii. [1,2,3,5,6] iii. [1,3,5] iv. [1,2,3,6]
67. What will be the output of the following code:
>>>l1=[1,2,3]
>>>l1.insert(2,25)
>>>l1
i. [1,2,3,25] ii. [1,25,2,3] iii. [1,2,25,3] iv. [25,1,2,3,6]
68. >>>l1=[10,20,30,40,50,60,10,20,10]
>>>l1.count(‘10’)
i. 3 ii. 0 iii. 2 iv. 9
69. Which operators can be used with list?
i. in ii. not in iii. both (i)&(ii) iv. Arithmetic operator only
70. Which of the following function will return the first occurrence
of the specified element in a list.
i. sort() ii. value() iii. index() iv. sorted()
71. Which of the statement(s) is/are correct.
i. Python dictionary is an ordered collection of items.
ii. Python dictionary is a mapping of unique keys to values
iii. Dictionary is mutable.
iv. All of these.

9
COMPUTER SCIENCE QUESTION BANK CLASS - XII

72. ………function is used to convert a sequence data type into


tuple.
i. List() ii tuple() iii TUPLE iv. tup()
73. It tup=(20,30,40,50), which of the following is incorrect
i. print(tup[3]) ii. tup[2]=55
iii. print(max(tup)) iv. print(len(tup))
74. Consider two tuples given below:
>>>tup1=(1,2,4,3)
>>>tup2=(1,2,3,4)
What will the following statement print(tup1<tup2)
i. True ii. False iii. Error iv. None of these
75. Which function returns the number of elements in the tuple
i. len( ) ii. max( ) iii. min( ) iv. count( )
76. Which function is used to return a value for the given key.
i. len( ) ii. get( ) iii. keys( ) iv. None of these
77. Keys of the dictionary must be
i. similar ii. unique iii. can be similar or unique iv. All of these
78. Which of the following is correct to insert a single element in a
tuple .
i. T=4 ii. T=(4) iii. T(4,) iv. T=[4,]
79. Which of the following will delete key-value pair for key=’red’
form a dictionary D1
i. Delete D1(“red”) ii. del. D1(“red”)
iii. del D1[“red”] iv. del D1
80. Which function is used to remove all items form a particular
dictionary.
i. clear( ) ii. pop( ) iii. delete iv. rem( )
81. In dictionary the elements are accessed through
i. key ii. value iii. index iv. None of these
82. Which function will return key-value pairs of the dictionary
i. key( ) ii. values( ) iii. items( ) iv. get( )

10
COMPUTER SCIENCE QUESTION BANK CLASS - XII

83. Elements in a tuple can be of ………….type.


i. Dissimilar ii. Similar iii. both i & ii iv. None of these
84. To create a dictionary, key-value pairs are separated
by…………
i. (;) ii. ( , ) iii. (:) iv. ( / )
85. Which of the following statements are not correct:
a. An element in a dictionary is a combination of key-value pair
b. A tuple is a mutable data type
c. We can repeat a key in dictionary
d. clear( ) function is used to deleted the dictionary.
i. a,b,c ii. b,c,d iii. b,c,a iv. a,b,c,d
86.Which of the following statements are correct:
a. Lists can be used as keys in a dictionary
b. A tuple cannot store list as an element
c. We can use extend() function with tuple.
d. We cannot delete a dictionary once created.
i. a,b,c ii. b,c,d iii. b,c,a iv. None of these
87. Like lists, dictionaries are……………..which mean they can be
changed.
i. Mutable ii. immutable iii. variable iv. None of these
88. To create an empty dictionary , we use
i. d=[ ] ii. d =( ) iii. d = {} iv. d= < >
89. To create dictionary with no items , we use
i. Dict ii. dict( ) iii. d = [ ] iv. None of these
90. What will be the output
>>>d1={‘rohit’:56,”Raina”:99}
>>>print(“Raina” in d1)
i. True ii. False iii. No output iv. Error

11
COMPUTER SCIENCE QUESTION BANK CLASS - XII

91. Rahul has created the a tuple containing some numbers as


>>>t=(10,20,30,40)
now he wants to do the following things help him
1. He want to add a new element 60 in the tuple, which
statement he should use out of the given four.
i. >>>t+(60) ii. >>>t + 60 iii. >>>t + (60,) iv. >>>t + (‘60’)
92. Rahul wants to delete all the elements from the tuple, which
statement he should use
i. >>>del t ii. >>>t.clear()
iii. >>>t.remove() iv. >>>None of these
93. Rahul wants to display the last element of the tuple, which
statement he should use
i. >>> t.display() ii. >>>t.pop()
iii. >>>t[-1] iv. >>>t.last()
94. Rahul wants to add a new tuple t1 to the tuple t, which statement
he should use
i. >>>t+t1 ii. >>>t.add(t1)
iii. >>>t*t1 iv. None of these
95. Rahul has issued a statement after that the tuple t is replace with
empty tuple, identify the statement he had issued out of the
following:
i. >>> del t ii. >>>t= tuple()
iii. >>>t=Tuple()iv. >>>delete t
96. Rahul wants to count that how many times the number 10 has
come:
i. >>>t.count(10) ii. >>>t[10]
iii. >>>count.t(10) iv. None of these
97. Rahul want to know that how many elements are there in the
tuple t, which statement he should use out of the given four
i. >>>t.count() ii. >>>len(t)
iii. >>>count(t) iv. >>>t.sum()

12
COMPUTER SCIENCE QUESTION BANK CLASS - XII

98. >>>t=(1,2,3,4)
Write the statement should be used to print the first three elements 3
times
i. >>>print(t*3) ii. >>>t*3
iii. >>>t[:3]*3 iv. >>>t+t
99. Match the output with the statement given in column A with
column B.
1. >>>tuple([10,20,30]) a. >>> (10,20,30)
2. >>>(“Tea”,)* 3 b. >>> 2
3. >>>tuple(“Item”) c. >>> ('Tea', 'Tea', 'Tea')
4. >>>print(len(tuple([1,2]))) d. >>> ('I', 't', 'e', 'm')
i. 1-b,2-c,3-d,4-a ii. 1-a,2-c,3-d,4-b
iii. 1-c,2-d,3-a,4-a iv. 1-d,2-a,3-b,4-c
100. Write the output of the following code:
>>>d={‘name’:’rohan’,’dob’:’2002-03-11’,’Marks’:’98’}
>>>d1={‘name’:‘raj’)
>>>d1=d.copy()
>>>print(“d1 :”d1)
i. d1 : {'name': 'rohan', 'dob': '2002-03-11', 'Marks': '98'}
ii. d1 = {'name': 'rohan', 'dob': '2002-03-11', 'Marks': '98'}
iii. {'name': 'rohan', 'dob': '2002-03-11', 'Marks': '98'}
iv. (d1 : {'name': 'rohan', 'dob': '2002-03-11', 'Marks': '98'})

13
COMPUTER SCIENCE QUESTION BANK CLASS - XII

Very Short Answer Type Questions: [2 mark]


1. 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 y in range [0,10]:
if x=y
print( x + y)
else:
print( x-y)
2. Rewrite the following program after finding and correcting
syntactical errors and underlining it.
a, b = 0
if (a = b)
a +b = c
print(c)
3. Rewrite the following code in python after removing all syntax
error(s). Underline each 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

14
COMPUTER SCIENCE QUESTION BANK CLASS - XII

4. Rewrite the following code in python after removing all syntax


error(s). Underline each correction done in the code.
Val = int(rawinput("Value:"))
Adder = 0
for C in range(1,Val,3)
Adder+=C
if C%2=0:
Print (C*10)
Else:
print (C*)
print (Adder)
5. Rewrite the following code in python after removing all syntax
error(s). Underline each correction done in the code.
25=Val
for I in the range(0,Val)
if I%2==0:
print( I+1):
Else:
print [I-1]
6. Rewrite the following code in python after removing all syntax
error(s). Underline each correction done in the code.
STRING=""WELCOME
NOTE""
for S in range[0,8]:
print (STRING(S))

15
COMPUTER SCIENCE QUESTION BANK CLASS - XII

7. Rewrite the following code in python after removing all syntax


error(s). Underline each correction done in the code.
a=int{input("ENTER FIRST NUMBER")}
b=int(input("ENTER SECOND NUMBER"))
c=int(input("ENTER THIRD NUMBER"))
if a>b and a>c
print("A IS GREATER")
if b>a and b>c:
Print(" B IS GREATER")
if c>a and c>b:
print(C IS GREATER)
8. Rewrite the following code in python after removing all syntax
error(s). Underline each correction done in the code.
i==1
a=int(input("ENTER FIRST NUMBER"))
FOR i in range[1, 11];
print(a,"*=", i ,"=",a * i)
9. Rewrite the following code in python after removing all syntax
error(s). Underline each correction done in the code.
a=”1”
while a>=10:
print("Value of a=",a)
a=+1

16
COMPUTER SCIENCE QUESTION BANK CLASS - XII

10. Rewrite the following code in python after removing all syntax
error(s). Underline each correction done in the code.
Num=int(rawinput("Number:"))
sum=0
for i in range(10,Num,3)
Sum+=1
if i%2=0:
print(i*2)
Else:
print(i*3 print Sum)
11. Rewrite the following code in python after removing all syntax
error(s). Underline each correction done in the code.
weather='raining'
if weather='sunny':
print("wear sunblock")
elif weather='snow':
print("going skiing")
else:
print(weather)
12. Write the modules that will be required to be imported to
execute the following code in Python.
def main( ):
for i in range (len(string)) ):
if string [i] = = ‘’ “
print
else:
c=string[i].upper()
print( “string is:”,c)
print (“String length=”,len(math.floor()))

17
COMPUTER SCIENCE QUESTION BANK CLASS - XII

13. Observe the following Python code very carefully and rewrite it
after removing all syntactical errors with each correction underlined.
DEF execmain():
x = input("Enter a number:")
if (abs(x)=x):
print ("You entered a positive number")
else:
x=*-1
print "Number made positive:"x execmain()
14. Rewrite the following code in python after removing all syntax
error(s).Underline each correction done in the code
x=integer(input('Enter 1 or 10'))
if x==1:
for x in range(1,11)
Print(x)
Else:
for x in range(10,0,-1):
print(x)
15. Rewrite the following code in python after removing all syntax
error(s). Underline each correction done in the code.
30=To
for K in range(0,To)
IF k%4==0:
print (K*4)
else
print (K+3)
16. What will be the error of the following code Snippet?
Lst =[1,2,3,4,5,6,7,8,9]
Lst[::2]=10,20,30,40,50,60
Print[Lst]

18
COMPUTER SCIENCE QUESTION BANK CLASS - XII

17. Find the error in following code. State the reason of the error
aLst={‘a’:1,’b’:2,’c’:3}
print(aLst[‘a’,’b’])
18. What will be the output of the following Code Snippet?
a =[1,2,3,4,5]
print(a[3:0:-1])
19. What do you mean by scope of variables?
20. Differentiate between the round( ) and floor( ) functions with the
help of suitable example.

19
COMPUTER SCIENCE QUESTION BANK CLASS - XII

Short Answer Type Questions: [3 mark]


1. Find output generated by the following code:
p=10
q=20
p*=q//3
q+=p=q**2
print(p, q)
2. Find output generated by the following code:
Str=”Computer”
Str=Str[-4:]
print(Str*2)
3. Find out the output of the Following –
x=20
x=x+5
x=x-10
print (x)
x, y=x-1,50
print (x, y)
4. Find out the output of the Following –
for a in range(3,10,3):
for b in range(1,a,2):
print(b, end=’ ‘)
print( )
5. FIND OUTPUT OF FOLLOWING
x=10
y=5
for i in range(x-y*2):
print("%",i)

20
COMPUTER SCIENCE QUESTION BANK CLASS - XII

6. Find output generated by the following code:


x="one"
y="two"
c=0
while c<len(x):
print(x[c],y[c])
c=c+1
7. Find output generated by the following code:
for i in range(-1,7,2):
for j in range(3):
print(i,j)
8. Find output generated by the following code:
string=”aabbcc”
count=3
while True:
if string[0]=='a':
string=string[2:]
elif string[-1]=='b':
string=string[:2]
else:
count+=1
break
print(string)
print(count)
9. Find output generated by the following code:
x="hello world"
print(x[:2],x[:-2],x[-2:])
print(x[6],x[2:4])
print(x[2:-3],x[-4:-2])

21
COMPUTER SCIENCE QUESTION BANK CLASS - XII

10. Find and write the output of the following python code:
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)
11. Find and write the output of the following python code :
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)

22
COMPUTER SCIENCE QUESTION BANK CLASS - XII

12. Find and write the output of the following python code:
Data = ["P",20,"R",10,"S",30]
Times = 0
Alpha = ""
Add = 0
for C in range(1,6,2):
Times= Times + C
Alpha= Alpha + Data[C-1]+"$"
Add = Add + Data[C]
print (Times,Add,Alpha)
13. Find and write the output of the following python code:
Text1="AISSCE 2018"
Text2=""
I=0
while I<len(Text1):
if Text1[I]>="0" and Text1[I]<="9":
Val = int(Text1[I])
Val = Val + 1
Text2=Text2 + str(Val)
elif Text1[I]>="A" and Text1[I] <="Z":
Text2=Text2 + (Text1[I+1])
else:
Text2=Text2 + "*"
I=I+1
print (Text2)

23
COMPUTER SCIENCE QUESTION BANK CLASS - XII

14. Find and write the output of the following python code:
TXT = ["20","50","30","40"]
CNT = 3
TOTAL = 0
for C in [7,5,4,6]:
T = TXT[CNT]
TOTAL = float (T) + C
print(TOTAL)
CNT-=1
15. Find output generated by the following code:
line = "I'll come by then."
eline = ""
for i in line:
eline += chr(ord(i)+3)
print(eline)
16. Find output generated by the following code:
line = "What will have so will"
L = line.split('a')
for i in L:
print(i, end=' ')
17. Find output generated by the following code:
p=5/2
q=p*4
r=p+q
p+=p+q+r
q-=p+q*r
print(p,q,r)

24
COMPUTER SCIENCE QUESTION BANK CLASS - XII

18. Find output generated by the following code:


a=(2 + 3) ** 3 – 6 / 2
b=(2 + 3) * 5// 4 + (4 + 6) / 2
c=12 + ( 3 * 4 – 6 ) / 3
d=12 % 5 * 3 + (2 * 6) // 4
print(a, b, c, d)
19. Find the output of the following:
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])
main()
20. Find the output of the following
L1 = [100,900,300,400,500]
START = 1
SUM = 0
for C in range(START,4):
SUM = SUM + L1[C]
print(C, ":", SUM)
SUM = SUM + L1[0]*10
print(SUM)

25
COMPUTER SCIENCE QUESTION BANK CLASS - XII

21. Find and write the output of the following python code:
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')
22. Find the output of the give program :
def Change(P ,Q=30):
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. Find the output of the give program :
x = "abcdef"
i = "a"
while i in x:
print(i, end = " ")

26
COMPUTER SCIENCE QUESTION BANK CLASS - XII

24. Give the output of the following code:-


list=['p','r','o','b','l','e','m']
list[1:3]=[]
print(list)
list[2:5]=[]
print(list)
25. Give the output of the following code:-
l1=[13,18,11,16,13,18,13]
print(l1.index(18))
print(l1.count(18))
l1.append(l1.count(13))
print(l1)
26. Find the error in following code. State the reason of the error.
aLst = { ‘a’:1 ,’ b’:2, ‘c’:3 }
print (aLst[‘a’,’b’])
27. Find the error in following code. State the reason of the error.
list1 =[1998, 2002, 1997, 2000]
list2 =[2014, 2016, 1996, 2009]
print"list1 + list 2 = : ", list1 +list2 #statement 1
print"list1 * 2 = : ", list1 *2 #statement 2
28. What is the output of the following:?
list1 = [1, 2, 3, 4, 5]
list2 =list1
list2[0] =0;
print("list1= : ", list1)
29. What is the output of the following:
data = [2, 3, 9]
temp = [[x forx in[data]]
for x in range(3)]
print(temp)

27
COMPUTER SCIENCE QUESTION BANK CLASS - XII

30. What is the output of the following:?


Temp =[‘Geeks’, ‘for’, ‘Geeks’]
for i in Temp:
print(i)
31. What will be the output?
1. d1 ={"john":40, "peter":45}
2. d2 ={"john":466, "peter":45}
3. d1 > d2
32. What will be the error of the following code Snippet?
Lst =[1,2,3,4,5,6,7,8,9]
Lst[::2]=10,20,30,40,50,60
Print[Lst]
33. Find the error in following code. State the reason of the error
aLst={‘a’:1,’b’:2,’c’:3}
print(aLst[‘a’,’b’])
34. What will be the output of the following Code Snippet?
a =[1,2,3,4,5]
print(a[3:0:-1])
35. What will be the output of the following Code Snippet?
fruit_list1 = ['Apple', 'Berry', 'Cherry', 'Papaya']
fruit_list2 = fruit_list1
fruit_list3 = fruit_list1[:]
fruit_list2[0] = 'Guava'
fruit_list3[1] = 'Kiwi'
sum = 0
for ls in (fruit_list1, fruit_list2, fruit_list3):
if ls[0] == 'Guava':
sum += 1
if ls[1] == 'Kiwi':
sum += 20
print (sum)

28
COMPUTER SCIENCE QUESTION BANK CLASS - XII

36. What will be the output of the following Code Snippet?


a = {(1,2):1,(2,3):2}
print(a[1,2])
37. What will be the output of the following Code Snippet?
my_dict = {}
my_dict[1] = 1
my_dict['1'] = 2
my_dict[1.0] = 4
sum = 0
for k in my_dict:
sum += my_dict[k]
print (sum)
38. 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
sum = 0
for k in my_dict:
sum += my_dict[k]
print (sum)
print(my_dict)
39. What will be the output of the following expression:
print(24//6%3, 24//4//2, 20%3%2)
40. Rearrange the following operators in Highest to Lowest Priority.
% , or, ==, not, =

29
COMPUTER SCIENCE QUESTION BANK CLASS - XII

Long Answer Type Questions: [4 mark]


1. Which string method is used to implement the following:
a. To count the number of characters in the string
b. To change the first character of the string in capital letter
c. To change lowercase to uppercase letter
d. To check whether the given character is letter or a number
2. Evaluate following expressions:
a) 18 % 4 ** 3 // 7 + 9
b) 2 > 5 or 5 == 5 and not 12 <= 9
c) 16%15//16
d) 51+4-3**3//19-3
e) 17<19 or 30>18 and not 19==0
3. Find the output of following codes:
1. t1=("sun","mon","tue","wed")
print(t1[-1])
2. t2=("sun","mon","tue","wed","thru","fri")
for i in range (-6,2):
print(t2[i])
3. t3=("sun","mon","tue","wed","thru","fri")
if "sun" in t3:
for i in range (0,3):
print(t2[i])
else:
for i in range (3,6):
print(t2[i])

30
COMPUTER SCIENCE QUESTION BANK CLASS - XII

4. Find the output of following codes:


1. t4=("sun", "mon", "tue", "wed", "thru", "fri")
if "sun" not in t4:
for i in range (0,3):
print(t4[i])
else:
for i in range (3,6):
print(t4[i])
2. t5=("sun",2,"tue",4,"thru",5)
if "sun" not in t4:
for i in range (0,3):
print(t5[i])
else:
for i in range (3,6):
print(t5[i])
3. t6=('a','b')
t7=('p','q')
t8=t6+t7
print(t8*2)
5. Find the errors:
1. t1=(10,20,30,40,50,60,70,80)
t2=(90,100,110,120)
t3=t1*t2
Print(t5[0:12:3])
2. t1=(10,20,30,40,50,60,70,80)
i=t1.len()
Print(T1,i)
3. t1=(10,20,30,40,50,60,70,80)
t1[5]=55
t1.append(90)
print(t1,i)

31
COMPUTER SCIENCE QUESTION BANK CLASS - XII

4. t1=(10,20,30,40,50,60,70,80)
t2=t1*2
t3=t2+4
print t2,t3
5. t1=(10,20,30,40,50,60,70,80)
str=””
str=index(t1(40))
print(“index of tuple is ”, str)
str=t1.max()
print(“max item is “, str)

32

You might also like