Unseen Passage

For Class 4 to Class 12

Class 12 Computer Science Sample Paper Term 1 Set A

Section A

1. Each key value pair in a dictionary is separated by a …………. 
(a) :
(b) ;
(c) –
(d) =

Answer

A

2. Dictionaries are also called
(a) mappings
(b) hashes
(c) associative arrays
(d) All of these

Answer

D

3. This method is used to delete key and respective value from dictionary.
(a) del()
(b) delete()
(c) pop()
(d) remove()

Answer

C

4. Which of the following errors will result the abnormal termination of program?
(a) Run-time
(b) Compile-time
(c) Semantic
(d) Syntax

Answer

A

5. Which exception classes raised when a generated error does not fall into any category?
(a) RuntimeError
(b) TypeError
(c) KeyError
(d) AttributeError

Answer

A

6. What is the output of following code?
a=10
b=2
print(a+10*2+b)
(a) 32
(b) 40
(c) 42
(d) 30

Answer

A

7. Identify the keyword from the following used in Python.
while, value, file, Lvalue, Rvalue
(a) value
(b) file
(c) while
(d) Lvalue

Answer

C

8. User can also add elements into an empty dictionary by
(a) dictionary_name=value
(b) dictionary_name[key]=value
(c) dictionary_name(key)=value
(d) dictionary_name{key}=value

Answer

B

9. Observe the output.
c=‘7’+2
print(c)
(a) 9
(b) 72
(c) 27
(d) Error

Answer

D

10. Find the output of the following code.
>>>complex (4, 8)
(a) 4+8j
(b) 4j+8
(c) 4j+8j
(d) Error

Answer

A

11. Which access mode can be used for opening a file for both appending and reading in a text file?
(a) a
(b) a+
(c) r
(d) r+

Answer

B

12. Which method specifies 6 characters the string should return?
(a) read(5+1)
(b) readline(6)
(c) readlines(6)
(d) read(6)

Answer

D

13. To display elements from beginning to a range use
(a) [: index]
(b) [index :]
(c) [index : 0]
(d) [: : index]

Answer

A

14. Which one of the following has the highest precedence in the expression?
(a) Exponential
(b) Addition
(c) Multiplication
(d) Parenthesis

Answer

D

15. Which are the two built-in functions to read a line of text from standard input, which by default comes from the keyboard?
(a) raw_input() and input()
(b) input() and scan()
(c) scan() and scanner()
(d) scanner()

Answer

A

16. What will be the output of the following Python code?
for i in range(1, int(3.0)):
print(i)

Class 12 Computer Science Sample Paper Term 1 Set A
Answer

A

17. What will be the output of the following Python code snippet?
d1 = {“Siya”:86, “Naman”:75}
d2 = {“Siya”:99, “Naman”:75}
d1 == d2
(a) True
(b) False
(c) None
(d) Error

Answer

B

18. To open a file ‘‘D:\Story.txt’’ for appending data, we use ………
(a) f = open(“D:\Story.txt”, “a”)
(b) f = open(“D:\Story.txt”, “rw”)
(c) f = open(file = “D:\Story.txt”, “w”)
(d) f = open(file = “D:\Story.txt”, “w+”)

Answer

A

19. Which of the following expressions results in an error?
(a) int(1101)
(b) int(‘1101’,23)
(c) int(1101,2)
(d) int(‘1101’)

Answer

C

20. Is the following Python code valid?
>>>tup1=(56, 25,36, 15)
>>> result=tup1.update(4,)
(a) Yes, tup1=(56, 25, 36, 15,4) and result=(56, 25, 36, 15,4)
(b) Yes, tup1=(56, 25, 36,15) and result=(56, 25, 36, 15,4)
(c) No, because tuples are immutable
(d) No, because wrong syntax for update() method

Answer

C

21. Which of the following is an invalid variable name?
(a) Add_num_3
(b) 1st_number
(c) test
(d) _num2

Answer

B

22. Observe the following code and identify the type of file.
File=open(“Mydata”, “a”)
File.write(“ABC”)
File.close()
(a) Binary file
(b) CSV file
(c) Text file
(d) None of these

Answer

C

23. Consider the declaration a=[2, 3, ‘Hello’, 23.0]. Which of the following represents the data type of ‘a’?
(a) string
(b) tuple
(c) dictionary
(d) list

Answer

D

24. Find the output from the following code.
list1=[2, 5, 4, 7, 7, 7, 8, 90]
del list1[2 : 4]
print(list1)
(a) [2, 5, 7, 7, 8, 90]
(b) [5, 7, 7, 7, 8, 90]
(c) [2, 5, 4, 8, 90]
(d) Error

Answer

A

25. What is the output of following code?
>>> dic={‘A’ : ‘One’, ‘B’ : ‘Two’, ‘C’ : ‘Three’}
>>>dic.keys()
(a) [‘B’, ‘C’, ‘A’]
(b) dict_keys [(‘B’, ‘C’, ‘A’)]
(c) dict_keys ([‘B’, ‘C’, ‘A’])
(d) keys ([‘B’, ‘C’, ‘A’])

Answer

C

Section B

26. What will be the output of following code?
l=[]
for i in range (20,40):
if (i% 7==0) and (i% 5 ! =0) :
l.append (str(i))
print(‘,’.join (l))
(a) 21
28
35
(b) 21
(c) 35
(d) Error

Answer

B

27. What is the output of following code?
def str (*a):
for i in a:
print(i)
str (* [“Hello”])
(a) Hello
(b) ‘‘Hello’’
(c) ‘H’, ‘e’, ‘l’, ‘l’, ‘o’
(d) Error

Answer

A

28. Identify the output of the following Python statement.
x = [[1, 2, 3, 4], [5, 6, 7, 8]]
y = x [0] [2]
print(y)
(a) 3
(b) 4
(c) 6
(d) 7

Answer

A

29. What is the output of following code?
def fun(Hello, n=2):
print(Hello * n)
fun(‘World’)
(a) World
(b) WorldWorld
(c) HelloHello
(d) HelloWorld

Answer

B

30. What is the output of following code?
a=10
def value(i):
c=0
c=a+i
return c
value(5)
(a) 5
(b) 10
(c) 15
(d) 105

Answer

C

31. What is the output of following code?
str1=“ARIHANT”
final=“ ”
for i in range(len(str1)):
if(i%2==0):
final=final+str1[i]
print(final)
(a) RHNT
(b) AIAT
(c) ARIH
(d) HANT

Answer

B

32. Siya is trying to write a list l1=[2, 5, 4, 3] on a binary file ‘hello.bin’. Consider the following code written by her.
import pickle
l1=[2, 5, 4, 3]
f=open (“hello.bin”,‘wb’)
pickle. —————— # Statement 1
f.close()
Identify the missing code in Statement 1.
(a) dump(f,l1)
(b) dump(l1,f)
(c) write(l1,f)
(d) write(f,l1)

Answer

B

33. What will be the output of the following Python code?
x = “123456”
i = “a”
while i in x:
x = x[:− 1]
print(i, end = “”)
(a) i i i i i i
(b) a a a a a a
(c) a a a a a
(d) None of the mentioned

Answer

B

34. What will be the output of the following Python code?
def test(): a=25
a=5
test()
a
(a) Error
(b) 25
(c) Junk value
(d) 5

Answer

D

35. What is the output of the following Python code?
a = 20
def test(a):
print(a)
a=5
test(a)
print(a)
(a) 20
20
(b) 20
5
(c) 20
40
(d) Error

Answer

A

36. What will be the output of the following Python code?
str1=“H#E#L#L#O”
b=list(str1.split( “#”,2))
print(b)
(a) [‘H’, ‘E’, ‘L#L#O’]
(b) [‘H’, ‘E’, ‘L’, ‘L’, ‘O’]
(c) [‘H#E’, ‘L#L#O‘]
(d) Error

Answer

C

37. What will be the output of the following Python code?
myfile = None
for i in range (4):
with open(“data.txt”, “w”) as my file
if i > 3:
break
print(myfile.closed)
(a) True
(b) False
(c) None
(d) Error

Answer

A

38. Evaluate the following expression and identify the correct answer.
25 + (6 − 4) * 2 + 4 / /3 * 4 − 1
(a) 32
(b) 42
(c) 22
(d) 33

Answer

A

39. What is the output of following code?
def work (a=10, b=20) :
s=a+b
print(s)
return
x=23
y=62
work(x, y)
(a) 30
(b) 85
(c) 33
(d) 82

Answer

B

40. What will be the output of following code?
import random
X=3
N=random.randint(1, X)
for i in range(N):
print (i, ‘#’, i+1)
(a) 3#4
(b) 4#5
(c) 5#6
(d) 2#3

Answer

D

41. Suppose the content of file ‘‘para.txt’’ is What will be the output of following code?
def count( ):
f=open (“para.txt”, “r”)
lines=0
l=f.readlines()
for i in l:
if i[0] ! = ‘W’ :
lines+=1
print(lines)
(a) 3
(b) 1
(c) 2
(d) Error

Answer

B

42. Consider the following code :
f=open(“Story”, “w+”)
f.write(“[email protected]#”)
f.seek(4, 3)
print(f.read(3))
What will be the correct output?
(a) def
(b) cde
(c) efg
(d) fgh

Answer

C

43. What is the output of following code?
list1=[4, 3, 7, 6, 4, 9, 5, 0, 3, 2]
l1=list1[1:10:3]
print(l1)
(a) [3, 7, 6]
(b) [3, 4, 0]
(c) [3, 6, 9]
(d) [7, 9,2]

Answer

B

44. What is the output of following code?
dic1={11, 12, 13}
for i in dic1:
print(i)
(a) 11 12 13
(b) {11, 12, 13} {11, 12, 13} {11, 12, 13}
(c) Error
(d) None

Answer

A

45. What is the output of following code?
x=15
globals() [‘x’]=63
print(x)
(a) 15
(b) 78
(c) 63
(d) Error

Answer

C

46. What will be the data type of s?
myfile=open(‘arihant’, ‘r’)
s=myfile.read()
print(s)
myfile.close()
(a) string
(b) list
(c) dictionary
(d) tuple

Answer

A

47. Observe the following code:
def fun(num):
—————— # Statement 1
print(fun(25))
Choose the correct option to fill up the blank in Statement 1.
(a) return 0
(b) return 1
(c) return num
(d) None of these

Answer

C

48. What is the output of following code?
t1=(3, 4, (6, 1), 7)
t=t1*2
print(t)
(a) (6, 8, (12, 2), 14)
(b) (3, 4, (6, 1), 7, 3, 4, (6, 1), 7)
(c) (3, 4, (6, 1), (6, 1), 7)
(d) Error

Answer

B

49. Identify the line which has an error.
i=0 # Line 1
while(i<25) # Line 2
print(“Hello”) # Line 3
i=i+1 # Line 4
(a) Line 1
(b) Line 2
(c) Line 3
(d) Line 4

Answer

B

Section C

Case Study Based Questions

Riya wrote a program to search any string in text file “school”. Help her to execute the program successfully.
def check() :
datafile = open (_______) #Line 2
found = input(“Enter any string to be searched : ”)
f = False
for line in _______ : #Line 5
if found in line :
f = _______ #Line 7
_______ #Line 8
return f
f = check ()
if(f = = _______) : #Line 11
print (“True”)
else :
print (_______) #Line 14

50. Riya should open which file to search any string?
(a) school.bin
(b) school.txt
(c) school.bat
(d) school.csv

Answer

B

51. Choose the correct option to fill up the blank in Line 5.
(a) f
(b) found
(c) datafile
(d) check()

Answer

C

52. Which value will be assign to f in Line 7?
(a) 0
(b) 1
(c) False
(d) True

Answer

D

53. Choose the correct option to fill up the blank in Line 8.
(a) break
(b) continue
(c) goto
(d) label

Answer

A

54. Choose the correct option to fill up the blank in Line 11.
(a) 0
(b) 1
(c) False
(d) True

Answer

D

55. Which variable or value will be print by last line?
(a) “True”
(b) “False”
(c) True
(d) False

Answer

B

Related Posts

error: Content is protected !!