Sample Paper 7: Computer Science

You might also like

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) 115

SAMPLE PAPER 7
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 of the following is invalid identifier?


(a) lambda (b) name1 (c) _SUM (d) FOR

2. Consider a declaration s = ‘‘computer’’, which of the following represents the data type
of s?
(a) list (b) tuple (c) dictionary (d) string

3. Given a list L1 = [3, 4, 5, 6, 8, 7, 7, 1, 2], what will be the output of print (L1 [3 : 7 : 2])?
(a) [6, 8, 7, 7, 1] (b) [6, 8, 7, 7]
(c) [6, 7] (d) (6, 7)

4. Which of the following is a path that contains the entire path to the file?
SAMPLE PAPER 7

(a) Relative path (b) Absolute path


(c) getcwd path (d) seek path

5. Which of the following option can be used to read the 5 bytes of text file ‘‘Para.txt’’?
(a) f = open(“Para.txt”) (b) f = open(“Para.txt”)
f.read( ) = 5 f.read(5)
(c) f = open (“Para.txt”) (d) f = open(“Para.txt”)
f.readline(5) f.readlines(5)
116 CBSE Sample Paper Computer Science Class XII (Term I)

6. Assume f is file object and to change the current position of file to 3 bytes forward.
Which statement will be used?
(a) f.seek(3, 1) (b) f.seek(1, 3)
(c) f.tell(3, 1) (d) f.tell(1, 3)

7. What is the use of ab access mode?


(a) Opens a file for reading in binary format
(b) Opens a file for writing in binary format
(c) Opens a file for appending in binary format
(d) Opens a file for both appending and reading in binary format

8. Type of sequence data type is/are


(a) string (b) list
(c) tuple (d) All of these

9. Which of the following loop is used for fixed number of iterations in Python?
(a) while loop (b) for loop
(c) do while loop (d) All of these

10. Consider the tuple t = (3, 4, 5, 8, 2). Identify the statement that will result in an error.
(a) print(t [1]) (b) t[3] = 9
(c) print(min(t)) (d) print(len(t))

11. Identify the category of the function that contains those functions which provide the
facility for doing some pre-defined operations.
(a) Built-in function (b) Library function
(c) Both (a) and (b) (d) None of these

12. Which of the following is used for standard output?


(a) sys.stdin (b) sys.stdout
(c) sys.out (d) sys.output

13. remove () method is used to ……… in Python.


(a) remove an existing file (b) remove a current file
(c) remove an exit file (d) remove a first file

14. Which type of the argument need to be included in the proper position?
(a) Default argument (b) Name argument
(c) Positional argument (d) Friendly argument

15. What is the use of seek() method in files?


(a) Sets the file’s current position at the offset
(b) Sets the file’s previous position at the offset
SAMPLE PAPER 7

(c) Sets the file’s current position within the file


(d) None of the mentioned

16. Which of the following is not an advantage of using modules?


(a) Provides a means of reuse of program code
(b) Provides a means of dividing up tasks
(c) Provides a means of reducing the size of the program
(d) Provides a means of testing individual parts of the program
CBSE Sample Paper Computer Science Class XII (Term I) 117

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


min(max(False,−13,−14),12,17)
(a) 12 (b) False
(c) − 13 (d) − 14

18. How are keyword arguments specified in the function heading?


(a) One star followed by a valid identifier
(b) One underscore followed by a valid identifier
(c) Two stars followed by a valid identifier
(d) Two underscores followed by a valid identifier

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


>>>tuple1 = (11, 12, 14, 13)
>>>tuple2 = (11, 12, 13, 14)
>>>tuple1 < tuple2
(a) True (b) False
(c) Error (d) None

20. In order to store values in terms of keys what basic data type can be used?
(a) List (b) Tuple
(c) String (d) Dictionary

21. Which is the correct operator for power?


(a) a^b (b) a**b
(c) a^^b (d) a*^b

22. What happens, if a local variable exists with the same name as the global variable you
want to access?
(a) Error
(b) The local variable is shadowed
(c) Undefined behavior
(d) The global variable is shadowed

23. Identify the arguments in following code.


def addition (a, b) :
print (a + b)
x = 5
addition(10, x)
(a) a, b (b) 10, x
(c) 5 (d) a, b , 10, x

24. Which type of data file stores the data in tabular form?
SAMPLE PAPER 7

(a) Text (b) Binary


(c) CSV (d) None of these

25. Which of the following is not included in logical errors?


(a) Using the wrong variable name
(b) Leaving out a keyword
(c) Getting operator precedence wrong
(d) Indenting a block to the wrong level
118 CBSE Sample Paper Computer Science Class XII (Term I)

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

26. What is the output of following code?


str1 = “Python Program”
print(str1 [3 : 7])
(a) hon (b) rog
(c) gra (d) tho

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


Welcome to study corner!
Hard work is the key of success.

What will be the output of the following code?


f = open (“para.txt”)
s = f.readlines( )
print(len(s))
f. close( )
(a) 2 (b) 11
(c) 4 (d) 7

28. Identify the output of following Python statement.


a = [[0, 1, 2], [3, 4, 5, 6]]
b = a [1] [2]
print (b)
(a) 2 (b) 1
(c) 4 (d) 5

29. Identify the output of following code.


a = 3
while a < 15 :
print (a , end = “ ”)
a = a + 2
(a) 3 5 7 9 11 13 15 (b) 3 5 7 9 11 13
(c) 1 3 5 7 9 11 13 15 (d) 1 3 5 7 9 11 13

30. Identify the output of following code.


list1 = [2, 3, 9, 12, 4]
list1.insert(4, 17)
list1.insert(2, 23)
print(list1 [−4])
SAMPLE PAPER 7

(a) 4 (b) 9
(c) 12 (d) 23

31. What is the output of following code?


def test (*x) :
for i in range(len(x) −1, −1, −1) :
print(x [i] + 2)
test(* [3, 4, 5, 9, 11, 2])
(a) [5, 4, 7, 11, 13, 2] (b) [3, 6, 5, 9, 11, 4]
(c) [5, 6, 7, 11, 13, 4] (d) [4, 13, 11, 7, 6, 5]
CBSE Sample Paper Computer Science Class XII (Term I) 119

32. Naman is trying to write a tuple tup1 = (5, 3, 4, 3) on a binary file ‘‘story.bin’’. Consider
the following code written by him.
import pickle
tup1 = (5, 3, 4, 3)
f = open(“story.bin”, ‘wb’)
pickle. _____ # Statement 1
f. close( )
Identify the missing code in Statement 1.
(a) dump (f,tup1) (b) dump (tup1, f)
(c) write (tup1,f) (d) load (f,tup1)

33. Evaluate the following expression and identify the correct answer.
10*4 // 2 + 4 − 2 //2 + 4 − 3 + 5 // 8
(a) 24 (b) 34 (c) 22 (d) 20

34. What will be the output of following code?


dic = {}
dic[(1, 2, 4)] = 8
dic[(4, 2, 1)] = 10
dic[(1, 2)] = 24
sum = 0
for i in dic :
sum = sum + dic[i]
print(sum)
(a) 40 (b) 42
(c) 34 (d) 18

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


x = [‘pq’, ‘rs’]
for i in x:
x.append(i.upper())
print(x)
(a) [‘PQ’, ‘RS’] (b) [‘pq’, ‘rs’, ‘PQ’, ‘RS’]
(c) [‘pq’, ‘rs’] (d) None

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


list1 = [5, 4, 9, 6, 2, 3]
for i in range(1, 6):
list1[i − 1] = list1[i]
for i in range(0, 6):
print(list1[i], end = “ ”)
SAMPLE PAPER 7

(a) 2 3 4 5 6 1 (b) 6 1 2 3 4 5
(c) 4 9 6 2 3 3 (d) 4 4 2 9 6 3

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


a=12
b=36
def test():
global b
a=21
b=33
120 CBSE Sample Paper Computer Science Class XII (Term I)

test()
print(a)
print(b)
(a) 12 (b) 13 (c) 12 (d) 36
33 12 36 21

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


def test():
a=12
print(a−1)
a=+1
test()
(a) 13 (b) 12 (c) 11 (d) Error

39. What is the output of the following Python code?


def test():
add += 1
return add
add = 0
print(test())
(a) 0 (b) 1 (c) − 1 (d) Error

40. What is the output of following code?


dic = {‘Hello’ : 2 , ‘How’ : 3, ‘Who’ : 9}
out = 1
for key in dic :
out = out * dic[key]
print(out)
(a) 54 (b) 27
(c) 6 (d) 18

41. What will be the output of following code?


l = []
for i in range(10, 35):
if(i% 7 ! = 0) and (i% 5 = = 0)
l.append(str(i))
print(‘,’.join(l))
(a) 10 (b) 10 (c) 10 (d) 15
15 15 15 20
20 20 20 25
25 25 25 30
30 30
SAMPLE PAPER 7

35

42. Find the output of the folloiwng code.


def test (a = 2, b = 7) :
a = a + b
b + = 2
print (a, b)
test (b = 3, a = 8)
(a) 11 5 (b) 3 8 (c) 2 7 (d) 5 15
CBSE Sample Paper Computer Science Class XII (Term I) 121

43. What is the output of following code?


def e( x, y, z) :
return (x > = y and x < = z)
e(2, 1, 0.8)
(a) 0 (b) 1 (c) False (d) True

44. What is the output of below code, when the list L contains [3, 5, 81, 7, 17]?
def test (L):
for i in range (len (L)) :
if(L [i]% 3 = = 0) :
L [i] = L [i] + 4
print(L)
(a) [3, 9, 81, 11, 21] (b) [5, 5, 31, 7, 17]
(c) [7, 5, 85, 7, 17] (d) [7, 9, 85, 11, 21]

45. What is the output of following code?


def test():
f=open(“Data.txt”,“r”)
count=0
x=f.read()
word=x.split()
for i in word:
if(i==“my”):
count=count+1
print(count)
test()
When the content of file ‘‘Data.txt’’ is
My first book was Me and My Family.
It gave me chance to be known to the world.
(a) 3 (b) 4
(c) 16 (d) 2

46. What is the output of following code?


import random
list1 = [2, 3, 4, 5, 6, 7, 9]
L = random.randint(1, 4)
U = random.randint(3, 5)
for K in range (L, U + 1):
print(list1 [K], end = “#”)
(a) 2 # 4 # 6 # (b) 3 # 4 # 6 #
SAMPLE PAPER 7

(c) 2 # 5 # 9 # (d) 2 # 3 # 4 #

47. Suppose the content of file is


Computer is an electronic device.

What is the output of following code?


f = open (“data.txt”, ‘r’)
file1 = f.read(13)
print(file1)
f.close( )
122 CBSE Sample Paper Computer Science Class XII (Term I)

(a) Computer is a (b) Computer


is
a
(c) Computer is an (d) Computer
is
an

48. What is the output of following code?


def test (a = 10, b = 20):
a + = 1
b = b − 1
return (a + b)
print(test (3), test ( ))
(a) 10 20 (b) 23 30 (c) 23 10 (d) 23 20

49. What is the output of following code?


def makenew (mystr):
newstr = “ ”
count = 0
for i in mystr:
if count % 2 ! = 0 :
newstr = newstr + str(count)
else:
if mystr.islower() :
newstr = newstr + upper(i)
else:
newstr = newstr + i
count + = 1
newstr = newstr + mystr[: 1]
print (newstr)
makenew(“sTUdeNT”)
(a) s1U3e5Ts (b) s1U3E5TS (c) S1U3E5TS (d) S1U3e5TS

Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.
Here is a program to check whether a passed string is palindrome or not.
def isPalindrome ( ) :
str1 = input(“Enter string”)
SAMPLE PAPER 7

left_pos = _____ # Statement 1


right_pos = len(str1)_____ # Statement 2
while _____ : # Statement 3
if not str1 [left_pos] = str1 [right_pos]:
_____ # Statement 4
left_pos+ = 1
_____ # Statement 5
_____ # Statement 6
CBSE Sample Paper Computer Science Class XII (Term I) 123

Answer the below questions to execute the program successfully.


50. Choose the correct option to fill up the blank in Statement 1.
(a) −1 (b) 1
(c) 0 (d) None

51. Choose the correct option to fill up the blank in Statement 2.


(a) −1 (b) 1
(c) True (d) False

52. Choose the correct option to fill up the blank in Statement 3.


(a) right_pos<=left_pos (b) right_pos> =left_pos
(c) right_pos= =left_pos (d) right_pos! =left_pos

53. Identify the statement after if condition is True in Statement 4.


(a) return 0 (b) return False
(c) return 1 (d) return True

54. Identify the statement for blank space in line marked as Statement 5.
(a) left_pos + = 1 (b) left_pos− =1
(c) right_pos− = 1 (d) right_pos+ =1

55. Identify the suitable value for blank space in line marked as Statement 6.
(a) False (b) True
(c) Flag (d) None

SAMPLE PAPER 7

You might also like