Computer Science Sample Paper Class 12 2021-22 Term 1

Computer Science Sample Paper Class 12 2021-22 Term 1 With Solution

Class-XII

Time: 1.30 hour/M.M.-35

General Instructions:

  • The question paper is divided into 3 Sections – A, B and
  • Section A, consist of 25 Questions (1-25). Attempt any 20
  • Section B, consist of 25 Questions (26-50). Attempt any 20
  • Section C, consist of 5 case study based Questions (50-55). Attempt all.
  • All questions carry equal

Section -A

1. Which of the following is an invalid variable?

a) my_string_1

b) 1st_string

c) Foo

d) _

 

2. What type of data is: arr = [(1,1),(2,2),(3,3)]?

a) Array of tuples

b) Tuples of lists

c) List of tuples

d) Invalid type

 

3. Write the output of the following code segment :

for i in range(-1,-6,-5):

        print(i*i)

a) 1                                              

b) 1 2

c) Error

d) Infinite loop

 

4. What is the output of the following program : print((1, 2) + (3, 4))

a) (1, 2), (3, 4)

b) (4, 6)

c) (1, 2, 3, 4)                            

d) Invalid Syntax

 

5. Which of the following statements are true?

a) When you open a file for reading, if the file does not exist, an error occurs

b) When you open a file for writing, if the file does not exist, a new file is created

c) When you open a file for writing, if the file exists, the existing file is overwritten with the new file

d) All of the mentioned

 

6. To open a file c:\scores.txt for appending data, we use ____________

a) outfile = open(“c:\\scores.txt”, “a”)

b) outfile = open(“c:\\scores.txt”, “rw”)

c) outfile = open(file = “c:\scores.txt”, “w”)

d) outfile = open(file = “c:\\scores.txt”, “w”)

 

 

7. What is the correct syntax of open() function?

a) file = open(file_name [, access_mode][, buffering])

b) file object = open(file_name [, access_mode][, buffering])

c) file object = open(file_name)

d) none of the mentioned

 

8. What is the two built-in functions to read a line of text from standard input, which is by default the keyboard?

a) Insert

b) Input

c) Read

d) Scanner

 

9. Which one of these is floor division?

a) //

b) /

c) %   

d) None of the above

 

10. What will be the output of the following Python code snippet?

d1 = {“john”:40, “peter”:45}

d2 = {“john”:466,”peter”:45}

d1 > d2

a) True

b) False

c) Error

d) None

 

11. Which of the following is not true about binary files?

a) Binary files are store in terms of bytes

b) When you open binary file in text editor will show garbage values

c) Binary files represent ASCII value of characters

d) All of the above

 

12. This method returns an integer that specifies the current position of the file object.

a) seek()

b) load()

c) position()

d) tell()

 

13. Which module is to be imported for working in binary file?

a) unpickle

b) pickle

c) pickling

d) unpickling

 

14. Which of the following items are present in the function header?

a) function name 

b) parameter list

c) return value

d) Both A and B

 

15. Which of the following function headers is correct?

a) def fun(a = 2, b = 3, c)

b) def fun(a = 2, b, c = 3)

c) def fun(a, b = 2, c = 3)

d) def fun(a, b, c = 3, d)

 

16. Which of the following would you relate to a function call made with an argument passed as its parameter?

a) function invocation

b) pass by value

c) pass by reference

d) pass by name

 

 

17. Which of the following is not a function of csv module?

a) readline()

b) writerow()

c) reader()

d) writer()

 

18. Which of these about a dictionary is false?

a) The values of a dictionary can be accessed using keys

b) The keys of a dictionary can be accessed using values

c) Dictionaries may or may not be ordered

d) None of the above

 

19. What is output for − 2 * 2 **3

a) 12

b) 64

c) 16 

d) 35

 

20. Which of the following statements are true?

a) When you open a file for reading, if the file does not exist, an error occurs

b) When you open a file for writing, if the file does not exist, a new file is created

c) When you open a file for writing, if the file exists, the existing file is overwritten with the new file

d) All of the mentioned

 

21. What is output of 33 == 33.0

a) False

b) True

c) 33

d) None of the above

 

22. Functions that do not return any value are known as

a) fruitful functions

b) void functions

c) library functions

d) user-defined functions

 

23. A variable created or defined within a function body is classified as-

a) Local

b) global

c) instance

d) build-in

 

24. Give output:

s=’Welcome to SPSEC’

print(s.find(‘come’), end= “”)

print(s.find(‘o’))

a) 4 3

b) 3 4

c) 3 3

d) 4 4

 

25. Give output:

s=’My’

s1=’City’

s2=s[:1]+s1[len(s1)-1:]

print(s2)

a) MyCity

b) CityMy

c) Mt d

d) My  

 

Section –B

26. To read the next line of the file from a file object infile, we use ____________

a) read(2)

b) infile.read()

c) readline()

d) infile.readlines()

 

27. Which of the following file mode is not a valid file mode?

a) rw  

b) ab

c) w+

d) r+

 

28. If we want to add more contents in an existing file, file must be opened in…………mode.

a) binary

b) append

c) write

d) it is not possible

 

29. Which method is used to convert Python objects for writing data in binary file?

a) write()

b) load()

c) store()

d) dump()

 

30. Which is not the valid mode for binary files?

a) r

b) rb

c) wb

d) wb+

 

31. Which of the following function is used to read the data in binary file?

a) read()

b) open()

c) dump()

d) load()

 

32. Suresh wants to open the binary file student.dat in read mode. He writes the following statement but he does not know the mode. Help him to find the same.

F=open(‘student.dat’, ____)

a) r

b) rb

c) w

d) wb

 

33. What is the output of the following program?

L= list(‘123456’)

L[0]=L[5]=0

L[3]=L[-2]

print (L)

a) [0, ‘2’, ‘3’, ‘4’, ‘5’, 0]

b) [‘6’, ‘2’, ‘3’, ‘5’, ‘5’, ‘6’]

c) [‘0’, ‘2’, ‘3’, ‘5’, ‘5’, ‘0’]

d) [0, ‘2’, ‘3’, ‘5’, ‘5’, 0]

 

34. What is the result of executing the following code?

number=5

while number <=5:

    if number <5:

        number=number+1

    print(number)

a) The program will loop indefinitely

b) The value of number will be printed exactly 1 time

c) The while loop will never get executed

d) The value of number will be printed exactly 5 times

 

35. What is the output of the following?

i=1

while True:

    if i%007==0:

        break

print(i)

i+=1

a) 1 2 3 4 5 6

b) 1 2 3 4 5 6 7

c) Error

d) None of these

 

36. What is the output of the following program?

L1=[ ]

L1.append([1,[2,3],4])

L1.extend([7,8,9])

print(L1[0][1][1]+L1[2])

 

a) Type Error: can only concatenate list (not “int”) to list

b) 12

c) 11

d) 38

 

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

def f1(a,b=[]):

          b.append(a)

          return b

print (f1(2,[3,4]))

a) [3,2,4]

b) [2,3,4]

c) [3,4,2]

d) Error

 

38. What is the output?

Y=[2,5J,6]

Y.sort()

a) [2,6,5J]

b) [5J,2,6]

c) [6,5J,2]

d) Error

 

39. What will be the output of the following program?

tuple=(“Check”)*3

print (tuple)

a) Unexpected

b) (3Check)

c) CheckCheckCheck

d) Syntax Error

 

40. Predict the output of the following code:

x,y=2,4

if(x+y= =10):

          print(“true”)

else:

            print(“false”)

 

a) true

b) false

c) no output

d) none

 

41. Choose the answer for statement 1

import_____________#statement 1

rec=[]

while True:

      rn=int(input(“Enter”))

      nm= input(“Enter”)

       temp=[rn,nm]

       rec.append(temp)

ch=input(“enter choice(Y/N)”)

if ch.upper== “N”:

              break

F=open(“stud.dat”,”____”)#statement 2

_________.dump(rec,f)#statement  3

______.close()#statement 4

a) csv

b) unpickle

c) pickle

d) load

 

 

42. Write the output of the First Print statements :

f=open(“data.txt”,’w’)

f.write(“Hello”)

f.write(“Welcome to my Blog”)

f.close()

f=open(“data.txt”, ‘r’)

d=f.read(5)

print(d) # First Print Statement

f.seek(10)

d=f.read(3)

print(d) # Second Print Statement

f.seek(13)

d=f.read(5)

print(d) # Third Print Statement

d=f.tell()

print(d) # Fourth Print Statement

 

a) Hello

b) Hell

c) Ello

d) None of the above

 

43. Ram opened a file in a certain mode. After opening the file, he forgot the mode. The interesting facts about that mode are ” If the file doesn’t exist, then a new file will be created” and “After opening file in that mode the file handle will be at the end of the file” Help him to identify the correct mode.

a) read mode

b) write mode

c) append mode

d) binary and read mode

 

44. What is the output of the following code.

def outerFun(a,b):

          def innerFun(c,d):

                   return c+d

          return innerFun(a,b)

res=outerFun(5,10)

print(res)

a) 15

b) Syntax Error

c) (5, 10)

d) (10,5)

 

45. What will be printed when the following code executes?

def  test(a,b=5):

print(a,b)

          test(-3)

a) -3, b

b) a, 5

c) -3, 5

d) -3 5

 

46. What value is printed when the following code is executed?

name=”Jane Doe”

def  myFunction (parameter):

value=”First”

value= parameter

print (value)

myFunction(“Second”)

 

a) Value

b) Second

c) Parameter

d) First

 

47. What will be the output of the following snippet?

f = None

for i in range (5):

with open (“data.txt”, “W”) as f:

if i > 2:

  break

print (f.closed)

 

a) True

b) False

c) None

d) Error

 

 

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

x=[‘ab’, ‘cd’]

for i in x:

       x.append(i.upper())

print(x)

a) [‘AB’, ‘CD’]

b) [‘ab’, ‘cd’, ‘AB’, ‘CD’]

c) [‘ab’, ‘cd’]

d) None of mentioned 

 

49. What is printed by the following atatements?

D={“cat”:12, “dog”: 10, “cow”: 20, “bear”:25}

print(25 in D)

a) True

b) False

c) Error

d) None

 

50. Given tup=(5,3,1,9,0), which of the following two statements will give the same output?

a) print(tup[:-1])

b) print(tup[0:5])

c) print(tup[0:4])

d) print(tup[-4:])

 

Section- C (Case Study Based Question)

Mr. Zack Sullivan loves programming. He joined an institute for learning. He is learning python. He learned all the python concepts like strings, lists, tuple, dictionaries etc. but he wants to learn file handling in python. He is trying to learn binary file handling. His teacher gave him partial code to write and read data from employee.dat having structure empno, name, salary. Help Zack to complete the code:

___________________ # statement 1

def addrecords():

fw= _____________ #statement 2

dict={}

ch=’y’

while ch==’y’:

eno=int(input(“enter employee number”))

nm= input(“enter employee name”)

sal=int(input(“enter employee salary”))

dict={‘empno’:eno,’name’:nm,’salary’:sal}

____________________ # statement 3

ch=input(“add more record”)

fw.close()

# function to diplay records

def display():

dict={}

fr= _____________ # statement 4

dict=____________ # statement 5

fr.close()

print(“data :”,dict)

 

Answer questions 51-55 based on above case study

51. Help Zack to import the module to perform binary file operation in statement 1.

a) csv

b) random

c) pickle

d) file

 

52. Which statement is used from the following for statement 2 to open the binary file in write mode?

a) open(“employee.dat”,’w’)

b) open(“employee.dat”,’wb’)

c) open(“employee.dat”,’w+’)

d) open(“employee.dat”,’r’)

 

53. Which statement is used from the following for statement 3 to write dictionary data created in above code, namely dict, is written in binary file employee.dat file?

a) dump(dict,fw)

b) pickle.write(dict,fw)

c) save(dict,fw)

d) pickle.store(dict)

 

54. Which statement is used from the following for statement 4 to open the binary file in read mode?

a) open(“employee.dat”,’r’)

b) open(“employee.dat”,’r+’)

c) open(“employee.dat”,’a’)

d) open(“employee.dat”,’rb’)

 

55. Compelete statement 5 to read data in dictionary namely dict from the opened binary file?

a) dict=pk.read(fr)

b) dict=pickle.load(fr)

c) load(dict,fr)

d) none of these

 

Don’t Miss Topics:

Class 12 Computer Science (083) Quick Revision

150+ Python Revision Tour MCQs

50+ Working with Function in Python MCQs

40+ Flow of control, conditional statements MCQs

40+ for loop in Python MCQs

40+ String Manipulation and function MCQs

40+ File Handling MCQs for Term 1

100+ Text File MCQs

60+ Binary File MCQs

40+ CSV File MCQs

50+ Data Structure MCQs

Leave a Reply

Your email address will not be published. Required fields are marked *