Class 12 Computer Science Sample Paper 2021-22 Term 1

COMPUTER SCIENCE (083)

SET-3

Maximum Marks: 35

Time Allowed: 90 Minutes

General Instructions:

The question paper is divided into 3 Sections – A, B and C. Section A, consist of 25 Questions (1-25). Attempt any 20 questions.

Section B, consist of 24 Questions (26-49). Attempt any 20 questions.

Section C, consist of 6 case study based Questions (50-55). Attempt any 5 questions. All questions carry equal marks.

 

Check Here for: Term 2 Sample Papers CS(083)

SECTION-A

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

1. If a function doesn’t have a return statement, which of the following does the function return?

a) int

b) null

c) None

d) An exception is thrown without the return statement

 

2. To open a file c:\test.txt for read data, we use

a) F = open(“c:\\test.txt”, “r”)

b) F = open(“c:\\test.txt”, “r+”)

c) F = open(file=”c:\test.txt”, “rw”)

d) F = open(file=”c:\\test.txt”, “w”)

 

3. To read the entire remaining contents of the file as a string from a file object infile, we use__

a) infile.read(2)

b) infile.readline()

c) infile.read()

d) infile.readlines()

 

4. Write the output of the given statements:

dict = {‘country’:[‘USA’, ‘UK’, ‘INDIA’, ‘NEPAL’],’Year’: [2012, 2012, 2013, 2014, 2014]}
print(dict.keys())

a) dict_keys([‘country’, ‘USA’])

b) dict_keys([‘country’, ‘UK’]).

c) dict_keys([‘Year’, ‘country’])

d) dict_keys([‘country’, ‘Year’])

 

5. Which of the following is an invalid statement ?

a) abc = 1, 000, 00

b) a b c=1000 2000 3000

c) a,b,c=1000,2000, 3000

d. a_b_c=1,000,000

 

6.Which among the following list of operators has the highest precedence ?

+,-,**,%,/,<<,>>,|

a) <<,>>

b) **

c) /

d) %

 

7. How many times will the following for loop execute?

for i in range (-1,7,-2):

         for j in range (3):

               print(i,j)

a) 0

b) 1

c) 7

d) 3

 

8. You have the following code segment:

String=”my”

String2=”work”

print(String 1.title()+ String2.upper())

a) my work

b) My Work

c) My WORK

d) MY WORK

 

9. Which of the following will raise an error if the given key is not found in the dictionary ?

a) del statement

b) pop()

c) popitem()

d. All of these

 

10. What is printed by the following statements?

D1={“cat”:12, “dog”:6, “elephant”:23,”bear”:20}

print(25 in D1)

a) True

b) False

c) Error

d) None

 

11. Given tp = (5, 3, 1, 9, 0) , Which of the following two statements will give the same output ?

i) print(tp[:-1])

ii) print(tp[0:5])

iii) print(tp[0:41)

iv) print(tp[-4:])

 

a) i & ii

b) ii & iv

c) i & iv

d) i & iii

 

12. Observe the following code and answer the question that follows:

File=open(“Mydata”,”a”)

_________#Blank 1

File.close()

Fill the Blank 1 with statement to write “ABC” in the file “Mydata”

a) File.Write(“ABC”)

b) File.writelines(“ABC”)

c) File.Writelines(“ABC”)

d) File.write(“ABC”)

 

 

13. What will be the output of the following codes snippet?

L=[12,15,3,9,11,18,5,22,27]

L[::2]=10,20,30,40,50

print (L)

a) [10, 15, 20, 9, 30, 18, 40, 22, 50]

b) [10, 15, 20, 9, 30, 18, 40, 50]

c) [10,20,30,40,50,12,15,3,9,11,18,5,22,27]

d) [10,20,30,40,50,18,5,22,27]

 

14. Which of the following options can be used to read the first 10 characters of a text file “Mine.txt” from the file object Filel?

a) File1.read(9)

b) File1.readlines(10)

c) Filel.Read(10)

d) File1.read(10)

 

15. Which of the following functions forces the writing of data on disc which is still pending in the output buffer?

a) read()

b) save()

c) flush()

d) load()

 

16. Consider a function header:

def Count Total(Itemname,Cost Qty,Disc=0.25)

Which of the following function calls is valid to invoke the given function header?

i) Count Total(10,Itemname=’Shirt”, 1000.0)

ii) Count Total(‘Shirt’,Cost-1500,Qty 2,Disc 0.30)

iii) Count Total(‘Shirt’.1000.0,5)

iv) Count Total(10, ‘Shirt’,Disc-0.25,1000.0)

 

a) i

b) ii

d) iv

 

17. Consider the statements given below:

Fileobj=open(“Real.txt”,”r”)

Fileobj.seek(30,0)

Choose the statement that best explains the second statement.

a) It will place the pointer at 30 bytes ahead of the current file pointerposition.

b) It will place the pointer 30 bytes behind from the end-of-file.

c) It will place the pointer 30 bytes behind from the beginning of the file.

d) It returns 30 characters from the 0th index.

 

18. Identify the output of the following Python statement.

LI=[[“Red”, “Green”],[“Blue”, “Yellow”,”Orange’],[‘Black’, ‘White’]]

print (4[2₂][0][3])

 

a)  ‘c’

b) ‘a’

c) Black

d) White

 

19. Suppose content of ‘myfile.txt’ file is :

Exception raised due to actual programming errors.

What will be the output of the following code?

File=open(‘myfile.txt’, ‘r’)

Txt=File.read()

print(File.read(10))

 

a. Exception

b. no errors.

c. Error

d. No Output

 

20. Consider a code :

F=open(“Tune.txt”,”r”)

A=F. _____

print(type(A))

Output: <class ‘list’>

Fill in the blanks with the appropriate function that will produce the output shown above.

a) read()

b) readlines()

c) read(10)

d) readline()

 

21. Assume you are reading from a text file from the beginning and you have to read 30 characters. Now you want to start reading from the 60th character from the beginning. Which function will you use to do the same?

a) seek(60,1)

b) seek(60,2)

c) seek(59,1)

d) seek(60,0)

 

22. Consider the statements given below:

import pickle

t1= (Pen’, “Pencil”, “Eraser”, “Notebook”)

with open(“Test.dat”, “wb’) as binfile:

        _____# Statement 1

Identify the missing code in Statement! that will write data from a list on the binary file.

 

a) pickle.load(mybinfile,t1)

b) pickle.dump(mybinfile,t1)

c) pickle.dump(t1,binfile)

d) pickle.load(t1.binfile)

 

 

23. Given a tuple T1=(2,4,7,9,6,5,1)

What will be the output of the following code ?

print (T1[-7],T1[-3]* 3,T1[1]%2)

a) 1 181

b) 221 0

c) 2 18 0

d) 2 18 1

 

24. Write the output of the following Python statements:

L1-[34,56,78,90,12,57]

L2=[98,45,66,43]

x=L2.pop(1)

L1.extend(L2)

L1.insert(3,101)

print(max(L1[2:9:2]))

a) 90

b) 78

c) 98

d) 91

 

25.Consider the given code and identify the incorrect output.

import random

n1=random.randint(0,4)

print(n1,end=’#’)

n2=random.randrange(3,5)

print(n2,end=’#’)

n3=random.randint(2,5)

print(n3)

 

a) 4#3#5

b) 1#4#4

c) 3#3#5

d) None of these

 

SECTION-B

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

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

def example(a):

a = a +’2′

a=a*2

return a

print (example(“hello”))

 

a) indentation Error

b) hello2

c) hello2hello2

d) cannot perform mathematical operation on strings

 

27. What will be the output of the 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 the mentioned.

 

28. What will be the result of the following code ?

x=’abcd’

for i in range(len(x)):

x= ‘a’

print(x,end=”)

a) a

b)aaaa

c) abcd abcd abcd

d) None of the mentioned

 

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

string=”my name is x”
for i in ”.join(string.split()):
print (i, end=”,” )

 

a) m,y,n,a,m,e,i,s,x,

b) no output

c) my, name, is, x,

d error

 

30. What possible output(s) are expected to be displayed on screen at the time of execution of the program from the following code? Also, specify the maximum values that can be assigned to each of the variables Lower and Upper.

 

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#

 

31. What possible output(s) are expected to be displayed on screen at the time of execution of the program from the following code? Also, specify the maximum and minimum values of variable N.

 

import random

x = 3

N=random.randitnt (1,x)

for i in range (N):

print (i, “#”, i+1)

a) 0#1
1#2
2#3

 

b) 1#2
0#1
2#3

 

c) 2#3
0#1
1#2

 

d) 3#4
0#1
2#3

 

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

list1=[0,5,2,7,0,0,9,0]

N=len (list1)

count =0

for i in range (N):

if list1 [i] ! 0:

list1 [count]=list[i]

count+=1

while count <N:

list 1 [count]=0

count +=1

print (list1)

 

a) [5, 2,0, 9, 0, 7, 0, 0]

b) [5, 2, 7, 9, 0, 0, 0, 0]

c) [5, 0, 7, 9, 0, 0, 0, 0]

d) [0, 2, 7, 9, 0, 5, 0, 0]

 

33. What is the result of the print statement.

Lst1=[“abe”,[10,20,30],50,”Together”]

print(Lst1[3:],Lst1 [::2],Lst1[1:2], Lst1[1][1])

 

a) [Together] [‘abc’, 50] [[10, 20, 30]] 20

b) [‘abc’] [‘Together’, 50] [[10, 20, 30]] 20

c) [‘Together’] [‘abc’, 50] [[10, 20, 20]] 30

d)  [‘Together’] [‘abe, 20] [[10, 20, 30]] 50

 

34. Write the output of the given program.

count=5

def count This():

global count

for i in (5,6,7):

count += 1 + i

count This()

print (count)

 

a) 25

b) 26

c) 27

d) 24

 

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

d1={“a”:10,”b”:2,”c”:3}

str1=”

for i in d1:

str1=str1+str(d 1][i])+’ ‘

str2=str1[:-1]

print(str2[::-1])

 

a) 32

b) 32 10

c) 3 201

d)

Error

 

36. Write the output of the given program:

X=”It is a self-replicating computer program”

F=open(“SMS.txt”,”w”)

F.write(X)

print(F.tell())

F.close()

 

a) 39

b) 40

c) 41

d)42

 

Complete the incomplete Code:

_________#Statement 1

Csvfile=open (____________, ______________,newline=’’) #Statement 2

CsvObj= csv.____ (_____) #Statement 3

RoWs = [ ]

Fields=[‘Empnumber’, ‘EmpName’, ‘EmpDesig’, ‘EmpSalary ]

Rows.append(Fields)

for I and range (5):

Empno =input (“Enter Employee No:”)

Name=input (“Enter Employee Name:”)

Design = input (“Enter Designation:”)

Salary=int (input (“Enter Salary:”))

Records =[_______]#Statement 4

Rows._______[________] #Statement 5

________’ ________(Rows) #Statement 6

Csvfile.close()

 

37. Identify the relevant module to import in the blank space i line marked as Statement 1.

a) import pickle

b) import txt

c) import csv

d) import cst

 

38. Identify the missing code for the blank space in line marked as statement 2.

a) “Employee.txt”, “rb”

b) “Employee.csv”, “w”

c) “Employee.csv”, “wb’

d) “Employee.dat”, “w”

 

39. Choose the function name (with argument) that should be used in the blank space of line marked as Statement 3.

a) writer (“Employee.csv”)

b) writer (Csv Obj)

c) read (“Csvfile”)

d) writer (Csvfile)

 

40. Identify the suitable code for blank space in line marked as Statement 4.

a) Empno,Name,Desig,Salary

b) “Empno, Name,Desig,Salary”

c) “Empno”, “Name”,”Desig”,”Salary”

d) “Empno-Name-Desig – Salary”

 

41. Identify the suitable code for blank space in the line marked as Statement 5.

a) insert (data)

b) delete(data)

c) append(records)

d) addrows(records)

 

42. Identify the suitable code for blank space in the line marked as statement 6.

a) Csvfile.load()

b) CsvObj.dumprow()

c) Csv Obj.writerows()

d) Records.reader()

 

43. Write the output of the following code:

def Changer(P,Q=20):

       P=P/Q

        Q=P%Q

        return P

A = 100

B = 10

A=Changer(A,B)

print (A,”$”,B)

A=Changer(A)

print (A,’$’,B)

a) 10.0 $ 10

0.5 $ 10

 

b) 10 $ 10.0

0.5 $ 10

 

c) 10.0 $10

10$ 0.5

 

d) 0.5 $10

10.0 $ 10

 

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

p=10

def power ():

global p

q=2

p=p**q

print (p)

power ()

print (p)

a) 10

10

b) 100

10

c) 10

100

d) none

 

45. 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 and activities that

Are important to you.

 

Write the output of the given  program.

 

F=open(“quotes.txt”,”r”)

F.seek(10)

print(F.read(5))

F.close()

 

a) ife y

b) life

c) a life

d) None

 

 

Complete the following code-

Here is the function to find the sum of the series given as:

S=a+ar+ar2+ar3………….arn

S = 0

def Series(a,r,n)…… # Line 1

       for i in range (0,n+1):

              S=S+…….. # Line 2

       print (“Sum:”,S)

       return

x=int(input(“Enter a no.”))

y=int(input(“Enter another no.”))

z=int (input(“Enter next no.”))

z=………………..#Line 3

print(“Sum=”,z)

 

46. Which symbol is used to terminate the function def’in Line 1.

a) ;

b) .

c) :

d) ”

 

47. Fill the blank in Line 2.

a) a*ri

b) a*r*i

c)a*r^i

d) a*r**i

 

48. Fill the blank in Line 3.

a) Series(x,y,z)

b) Series(a,r,n)

c) series(a,r,n)

d) series(x,y,z)

 

49. What will be the result of z in the above function if the values passed are 5,5,5.

a) 19530

b) 19350

c) 15930

d) None

 

SECTION-C

Case Study based Questions:

This section consists of 6 Questions (50-55) Attempt any 5 questions.

 

The owners of the Food mill store wish to generate a bill for each transaction using a binary file. In order to do this, they have recruited a friend who is learning python. The friend has made a file called ‘foodmill.dat’ that contains information like itemno, item Name, Qty and Price in order to compute Total Amount, but is having problems finishing it. Assist the friend in finishing the code.

Incomplete code:

import__________#Statement 1

File=”________(“foodmill.dat”._______’)#Statement 2

ch=’y’

while True :

   Itemno= input (“Enter Item No:”)

   Product=input(“Enter Product Name :”)

    Qty =int (input(“Enter Quantity:”))

    Price=int(input(“Enter Price:”))

    Amount=Qty *Price

    Records =[Itemno,Product, Qty,Price,Amount]

    pickle._________ #Statement 3

    ch=input(“Do you want to buy more……..”)

     if ch== ‘y’ or ch==’y”:

                   continue

      else:

                  break

File.close()

def Total_Amount():

        F=open (foodmill.dat ‘dat”, “rb+)

       Total_Amt=0

        try :

                 While True:

                 ‘R=________#Statement 4

                        _________________#Statement 5

                         print (“you have purchased”,R[2], R[1], “of Price”,”R”, R[3]. “and amount is”, R[4])

      __________________:#Statement 6

            F.close()

print(“Total Amount is Rs”, total_Amt)

 

50. Identify the relevant module to import in the bi, k space in line marked as statement 1.

a) pickle

b) bin

c) tsv

d) csv

 

51. Identify the code to open the file alongwith the access mode so that every time the program is run, new customer records will be added in Statement 2.

a) open ‘rb’

b) open ‘wb’

c) open ‘r’

d) write ‘w’

 

52. Identify the suitable code for blank space in the line marked as statement 3.

a) Load (records, file)

b) dump (Records, file)

c) dumps (record, file)

d) load(file,records)

 

53. Identify the suitable code for blank space in line marked as statement 4.

a) pickle.load(F)

b) pickle.dump(f)

c) pickle.load(R)

d) pickle.load(f)

 

54.Identify the suitable code to calculate the total Amount in the line marked as Statement 5.

a) total_amount = R [4]

b) total_Amt = R[3] +R [4]

c) total_amount+=R[4]

d) total_amount=R[4]*2

 

55.Identify the suitable keyword to handle the exception (if any) that occurs during execution the try clause.

a) catch

b) except

c) stop

d) exception

 

 

Term 2 Sample Papers

Copywrite © 2020-2024, CBSE Python,
All Rights Reserved
error: Content is protected !!