Sample Paper 2: Computer Science

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

CBSE Sample Paper Computer Science Class XII (Term I) 55

SAMPLE PAPER 2
COMPUTER SCIENCE
A Highly Simulated Practice Questions Paper
for CBSE Class XII (Term I) Examination

Instructions
1. This question paper is divided into three sections.
2. Section - A contains 25 questions (1-25). Attempt any 20 questions.
3. Section - B contains 24 questions (26-49). Attempt any 20 questions.
4. Section - C contains 6 case study based questions (50-55). Attempt any 5 questions.
5. Each question carries 0.77 mark.
6. There is no negative marking.

Maximum Marks : 35
Roll No. Time allowed : 90 min

Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.

1. Which is a way to convey a Python object into a character stream.


(a) Pickling (b) Unpickling (c) dump() method (d) load() method

2. Which character is used to create a new file in csv?


(a) r (b) w (c) r+ (d) x

3. Which path does not start with a leading forward slash?


(a) Relative (b) Absolute (c) Both (a) and (b) (d) None of these

4. Which of the following operators in Python are used to determine whether a value is of
a certain class or type?
(a) Identity operators (b) Membership operators
SAMPLE PAPER 2

(c) Comparison operators (d) All of these

5. This function converts all uppercase letters in string to lowercase letters.


(a) upper() (b) lower() (c) isupper() (d) islower()

6. List can be created to put the elements in


(a) [] (b) {} (c) () (d) None of these

7. Which of the following are sequence of character data?


(a) Lists (b) Tuples (c) Strings (d) Dictionaries
56 CBSE Sample Paper Computer Science Class XII (Term I)

8. List, dictionary and sets are


(a) mutable (b) immutable (c) Both (a) and (b) (d) None of these

9. The process of converting a data type into another data type is known as ............ .
(a) expression (b) operator
(c) type conversion (d) comparison

10. In complex number a + ib, b represents as


(a) real part (b) imaginary part
(c) special part (d) None of these

11. To print all elements of tuple in reverse order using ............


(a) [: – 1] (b) [: : – 1] (c) [1 : : ] (d) [: : 1]

12. Which function is used to convert string into tuple?


(a) string() (b) tup() (c) tuple() (d) str_tuple()

13. Which statement is a sequence of more than one statements?


(a) Control statement (b) Compound statement
(c) Single statement (d) Sequence statement

14. Which of the following is a step-by-step process of solving a well defined


computational problem?
(a) Algorithm (b) Pseudocode (c) Flowchart (d) Decision table

15. ............ are drawn using certain special purpose symbols.


(a) Algorithm (b) Pseudocode
(c) Flowchart (d) Decision table

16. Which of the following function is a built-in function in Python?


(a) myFunc() (b) test() (c) def() (d) print()

17. What will be the output of the following Python expression?


round(8.695)
(a) 8.6 (b) 9 (c) 8 (d) 8.7

18. What will be the output of the following Python code?


x = [‘AB’, ‘CD’]
for i in x:
i.lower()
print(x)
(a) [‘ab’, ‘cd’] (b) [‘AB’, ‘CD’]
(c) [None, None] (d) None of the mentioned
SAMPLE PAPER 2

19. Suppose list1 is [2445,133,12454,123], what is max(list1)?


(a) 2445 (b) 133 (c) 12454 (d)123

20. What will be the output of the following Python code?


x = “abcdef”
i = “a”
while i in x:
print(‘i’, end = “ ”)
(a) No output (b) i i i i i i ... (c) a a a a a a... (d) a b c d e f
CBSE Sample Paper Computer Science Class XII (Term I) 57

21. Which of the following operators has its associativity from right to left?
(a) + (b) //
(c) % (d) **

22. What will be the output of the following Python code?


>>> a=(l,2,(4,5))
>>> b=(l,2,(3,4))
>>> a<b
(a) False
(b) True
(c) Error, < operator is not valid for tuples.
(d) Error, < operator is valid for tuples but not if there are sub-tuples.

23. What will be the output of the following Python code snippet?
d1 = {“Neha”:86, “Yash”:92}
d2 = {“Neha”:86, “Yash”:88}
d1 > d2
(a) True (b) False (c) Error (d) None

24. What will be the output of the following Python code?


Dic1={}
Dic1[2]=85
Dic1[1]=[22,23,24]
print(Dic1[1][1])
(a) [22,23,24] (b) 23 (c) 22 (d) Error

25. What will be the output of the following Python code?


dic1 = {0: ‘One’, 1: ‘Two’, 2: ‘Three’}
for x, y in dic1:
print(x, y)
(a) 0 1 2 (b) One Two Three
(c) 0 One 1 Two 2 Three (d) Error

Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.

26. What is the output of the following code?


t1=(70, 56, ‘Hello’, 22, 2, ‘Hi’, ‘The’, ‘World’, 3)
print(t1 [2:4])
(a) (56, ‘Hello’) (b) (‘Hello’, 22)
SAMPLE PAPER 2

(c) (‘Hello’, 22,2) (d) (56, ‘Hello’, 22)

27. Suppose the content of file ‘‘arihant.txt’’ is


Welcome to Arihant!
Welcome to your one-step solutions for all your study, practice and
assessment needs for various competitive & recruitment examinations
and school segment.
58 CBSE Sample Paper Computer Science Class XII (Term I)

What will be the output of the following code?


myfile=open(“arihant.txt”,“r”)
s=myfile.read(10)
print(s)
s1=myfile.read(15)
print(s1)
myfile.close()
(a) Welcome to (b) Welcome to
Welc Arihant!
(c) Welcome to (d) Welcome
Arihant! to
Welc Arihant

28. Identify the output of following code.


for i in range(4):
if i == 4:
break
else:
print(i)
else:
print(“Welcome”)
(a) 0 (b) 1 (c) Error (d) None
1 2
2 3
3 Welcome
Welcome

29. What will be the output of the following Python code snippet?
x = ‘abcd’
for i in range(len(x)):
print(x)
x = ‘a’
(a) a (b) abcd abcd abcd abcd
(c) a a a a (d) None of the mentioned

30. Identify the output of the following Python statement.


x=0
for i in range (1, 12, 3):
x+=i+3
print(x)
(a) 31 (b) 32 (c) 33 (d) 34
SAMPLE PAPER 2

31. Identify the output of the following Python code.


def test(val):
val[1]=20
a=[2, 3, 4]
test(a)
print(a)
(a) [2, 20] (b) [20, 3] (c) [2, 3, 20, 4] (d) [2, 20, 4]
CBSE Sample Paper Computer Science Class XII (Term I) 59

32. Sohan is a student of Class 12th. He got an assignment on Python language, in which
one question is
Write a tuple test = (3, 4, 8, 11, 2) on a binary file hello.bin. Consider the following code
written by him.
import pickle
test=(3, 4, 8, 11, 2)
file=open(“hello.bin”, “wb”)
pickle. —————————— # line 1
file.close()
Identify the missing code in line 1.
(a) dump (file, test) (b) dump (test, file)
(c) write (test, file) (d) load (file, test)

33. Suppose the content of file “vowel.txt” is


Welcome to Arihant!
Welcome to your one-step solutions for all your study, practice and
assessment needs for various competitive & recruitment
examinations and school segment.

What will be the output of following code?


def count():
vow=0
f=open(“vowel.text”, “r”)
N=f.read()
M=N.split()
for i in M:
if(i==“a” or i== “e” or i==“i” or i==“o” or i==“u”):
vow=vow+1
f.close()
(a) 60 (b) 58 (c) 59 (d) 54

34. Find the output of the following code.


def Func (a = 1, b = 2):
a = a+ b
b + = 1
print (a , b)
Func (b = 4, a = 5)
(a) 9 5 (b) 4 5
(c) 4 9 (d) Error

35. Evaluate the following expression and identify the correct answer.
SAMPLE PAPER 2

2*3//4 + 4//4 + 8 − 2 + 5//8


(a) 14 (b) 8
(c) 10 (d) 12

36. What will be the output of the following Python code?


def power(a, b=4):
r = 1
for i in range(b):
r = r * a
return r
60 CBSE Sample Paper Computer Science Class XII (Term I)

print power(5)
print power(5, 5)
(a) 625 (b) 625 (c) 3125 (d) Error
3125 625 3125

37. What will be the output of the following Python code?


def printMax(a, b):
if a> b:
print(a, ‘is maximum’)
elif a == b:
print(a, ‘is equal to’, b)
else:
print(b, ‘is maximum’)
printMax(33,94)
(a) 33 is maximum (b) 94
(c) 94 is maximum (d) Error

38. What will be the output of following code?


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=“#”)
(a) 10#40#70# (b) 30#40#50#
(c) 50#60#70# (d)40#50#70#

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


list1 = [11, 12, 13, 14, 15]
for i in range(1, 5):
list1[i−1] = list1[i]
for i in range(O, 5):
print(list1[i] ,end = “ ”)
(a) 15 15 1112 13 (b) 15 1112 13 14
(c) 12 13 14 15 11 (d) 12 13 14 15 15

40. What will be the output of the following Python code?


myFile = open(“story.txt”, “wb”)
print (“Name of the file:”, myFile.name)
myFile.flush()
myFile.close()
SAMPLE PAPER 2

(a) Compilation error (b) Runtime error


(c) No output (d) Flushes the file when closing them

41. Find the output of the following code from given options.
def calcresult ():
i=9
while i > 1 :
if (i % 2 = = 0):
x = i% 2
i = i− 1
CBSE Sample Paper Computer Science Class XII (Term I) 61

else:
i = i − 2
x = i
print (x * * 2)
(a) 81 (b) 81 (c) 81 (d) 49
49 49 49 25
25 25 25 9
9 9 1
1

42. Suppose the content of file ‘‘para.txt’’ is


Nothing is more terrifying than fearlessness

What will be the output of the following code?


file = open(“para.txt”)
val = file.read()
print(len(val))
file.close()
(a) 44 (b) 39 (c) 45 (d) Error

43. What will be the output of following code?


def mean (* args):
total = 0.0
for v in args :
total + = v
return (total / len (args))
mean (* [1, 2, 3, 4])
(a) 2 (b) 3 (c) 2.5 (d) 3.5

44. A text file “Quotes.txt” has the following data written in it.
Living a life you can be proud of
Doing your best
Spending your time with people

What will be the output of the following code?


def COUNT ( ):
s=open (“Quotes.txt”, “r”)
f=s.read( )
z=f.split( )
count=0
SAMPLE PAPER 2

for i in z:
count=count+1
print (count)
(a) 14 (b) 15 (c) 16 (d) 29

45. What will be the output of the following Python code snippet?
a={}
a[1] = 1
a[‘1’] = 2
a[1]=a[1]+1
62 CBSE Sample Paper Computer Science Class XII (Term I)

count = 0
for i in a:
count+= a[i]
print(count)
(a) 1
(b) 2
(c) 4
(d) Error, the keys cannot be a mixture of letters and numbers

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


i=0
def change(i):
i=i+1
return i
change(1)
print(i)
(a) 1 (b) Nothing is displayed (c) 0 (d) Error

47. What is the output of the code?


z = 100
def f():
global z
print(‘z is:’, z)
z=50
print(‘New value of global z is:’, z)
f()
print(‘Value of z is:’, z)
(a) z is : 100
New value of global z is: 100
Value of z is : 100
(b) z is : 100
New value of global z is: 100
Value of z is : 50
(c) z is : 100
New value of global z is: 50
Value of z is : 100
(d) z is : 100
New value of global z is: 50
Value of z is : 50
SAMPLE PAPER 2

48. Suppose the content of text file ‘‘para.txt‘’ is


Muskan Verma
Rahul Sinha
Arihant
What will be the data type of s?
file=open (“para.txt”, “r”)
s=file.read()
file.close()
(a) string (b) list (c) tuple (d) sets
CBSE Sample Paper Computer Science Class XII (Term I) 63

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


dic1= {‘One’ :1, ‘Two’ : 2, ‘Three’:3}
s=(list(dic1.values())
print(s)
(a) [‘One’, ‘Two’, ‘Three’] (b) [1, 2, 3]
(c) [3] (d) [‘One’ : 1, ‘Two’ : 2, ‘Three’ : 3]

Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.

def makenew (mystr):


newstr = “ ”
count = 0
for i in ____ : #line 1
if count % 2 ! = 0 :
newstr = newstr + str (____) #line 2
else:
if ____ (i): #line 3
newstr = newstr + upper(i)
else:
newstr = newstr + ____ #line 4
count + = 1
newstr = ____ + mystr[: 1] #line 5
print (“The new string is:”, newstr)
____ (“sTUdeNT”) #line 6
50. Choose the correct option to fill up the blank in line 1 as marked.
(a) mystr (b) newstr (c) mystr +1 (d) mystr −1

51. Choose the correct option to fill up the blank in line 2 as marked.
(a) i (b) count (c) i + 1 (d) count +1

52. Choose the correct option to fill up the blank in line 3 as marked.
(a) lower (b) upper (c) islower (d) isupper

53. Choose the correct option to fill up the blank in line 4 as marked.
(a) 1 (b) i * 2 (c) i/2 (d) i

54. Choose the correct option to fill up the blank in line 5 as marked.
SAMPLE PAPER 2

(a) newstr (b) count (c) i (d) str

55. Choose the correct option to fill up the blank in line 6 as marked.
(a) newstr (b) str (c) makenew (d) mystr

You might also like