# Class 12 Computer Science Sample Paper Term 1 With Solutions Set B

Please refer to Class 12 Computer Science Sample Paper Term 1 With Solutions Set B provided below. The Sample Papers for Class 12 Computer Science have been prepared based on the latest pattern issued by CBSE. Students should practice these guess papers for class 12 Computer Science to gain more practice and get better marks in examinations. The Term 1 Sample Papers for Computer Science Standard 12 will help you to understand the type of questions which can be asked in upcoming examinations.

## Term 1 Sample Paper for Class 12 Computer Science With Solutions Set B

Question. Consider a tuple T1=(2,3,{1:‘One’,2:‘Two’,3:‘Three’}). Identify the statement that will result in an error.
(a) print(T1)
(b) print(T1)
(c) print(2 in T1)
(d) print(len(T1))

A

Question. What will be the output of the following code if the contents of the file ‘File1.txt’ are:
String may refer to
fileobj = open(“File.txt”,’w’)
fileobj.write(“Letters\n”)
fileobj.write(“Numbers\n”)
fileobj.write(“Special characters”)
fileobj.close()
fileobj = open(“File.txt”,’r’)
fileobj.close()
fileobj.close()
(a) Special Characters
(b) letters
(c) String may refer to/Letters/Numbers/Special Characters
(d) Letters/Numbers/Special Characters

D

Question. Fill in the blanks with the appropriate operator to obtain the output.
31 ……… 3 = 10
(a) /
(b) %
(c) //
(d) ^

C

Question. What will be the output of the following code snippet?
Tup1=(9,3,5,[1,2,3],8)
Tup1=10
print(Tup1)
(a) Error
(b) (9, 3, 5, [1, 10, 3], 8)
(c) (9, 3, 5, [1, 10, 2, 3], 8)
(d) (3, 3, 3, [1, 10, 3], 10)

B

Question. Consider a statement
fileobj = open(“myblog.txt”, ‘r’)
Which of the following options can be used to print the last line of a text file ‘myblog.txt’?

B

Question. Write the output of the following Python statements:
L1 = [1,2,3,4,5]
L2=[4,5,6]
L1.extend(L2)
L1.insert(4,9)
L1[-5:-2]
(a) [1, 2, 3]
(b) [4, 5, 6, 9]
(c) [9, 5, 4, 5]
(d) [9, 5, 4]

D

Question. Consider the content of ‘rhyme.txt’ file is:
Knees and toes.
Knees and toes.
And eyes, and ears, and mouth, and nose.
Knees and toes.
What will be the output of the following code?
fileobj=open(‘rhyme.txt’,’r’)
count = 0
for i in l:
if(i==’H’):
count=count+1
print(count)
fileobj.close()
(a) 3
(b) 6
(c) 2
(d) 1

A

Question. What will be the output of the following code?
import pickle
list1 = [‘Red’,’Green’,’Orange’,’Yellow’,’Brown’]
fobj = open(“file.dat”,’wb’)
l=pickle.dump(list1,fobj)
fobj.close()
fobj = open(“file.dat”,’rb’)
for i in range(len(l)-1,0,-1):
print(l[i])
fobj.close()
(a) Red / Green / Orange/Yellow/Brown
(b) Brown / Yellow/Orange/Green
(c) Yellow / Orange/Green/Red
(d) Brown / Yellow/Orange/Green/Red

B

Question. Which of the following statements is used to open a text file to add new contents at the end of the already existing text file named ‘mydiary.txt’?
(a) with open(“’mydiary.txt”, ‘w’) as fileobj:
(b) fileobj = open(“mydiary.txt”, ‘a’)
(c) with open(“mydiary.txt”,’a’) as fileobj:
(d) with open(“mydiary”, ‘r+’) as fileobj:
(a) Only (a)
(b) Only (b)
(c) Both (b) and (c)
(d) Both (a) and (d)

C

Question. Which of the following is the default delimiter character in CSV file?
(a) /
(b) ,
(c) :
(d) %

B

Question. Which of the following statements is correct regarding csv.writer() object for storing data in the csv file?
(a) Removes the delimiter characters from the data before storing it.
(b) Returns a writer object which writes data into CSV file.
(c) Creates rows
(d) Creates columns

B

Question. Write the output of the following code snippet.
x = ‘Rain’
z = 3
print(len(x) * z)
(a) 10
(b) RainRainRain
(c) 12
(d) 3 3 3

C

Question. What is the output of the following code?
Text = ‘Happy hour12-3’
L= “”
for i in range(len(Text)):
if Text[i].isupper():
L=L+Text[i].lower()
elif Text[i].islower():
L=L+Text[i].upper()
elif Text[i].isdigit():
L=L+(Text[i]*2)
else:
L=L+’#’
print(L)
(a) hAPPY#HOUR1122#33
(b) Happy#hOUR12#3
(c) hAPPY#HOUR112233
(d) Happy Hour11 22 33 #

A

Question. “The information is stored in machine-readable format and pickle module is used for reading and writing data from/in the file.” Identify the type of file discussed in the above lines?
(a) Text files
(b) CSV files
(c) Binary file
(d) All of the above

C

Question. What will be the output of the following code?
def Sum():
global p
p=p+7**2
print(p, end= ‘#’)
p = 10
print(p,end= ‘@’)
Sum()
print(p)
(a) 10@59#59
(b) 59@10#59
(c) 59@59#10
(d) 10@10#10

A

Question. Assume that you are writing in a text file; now you want to identify where the cursor is currently at in the file. Which function will you use for the same?
(a) seek()
(b) hide()
(c) tell()
(d) type()

C

Question. Which of the following statements is correct regarding file access modes?
(a) In ‘r’ mode, we can read and write data from/in the file.
(b) In ‘a’ mode, the existing data will be over-written if the file exists.
(c) In ‘w’ mode, the data in the file is retained and new data will be appended to the end.
(d) In ‘a+’ mode, both reading and writing operations can take place and new data is appended to the end of the existing file.

D

Question. Identify which function is used to write data in the binary file?
(a) seek()
(c) dump()
(d) write()

C

Question. Suppose the content of ‘Student.dat’ file is:

What will be the output of the given code?
def Total_Amount():
f= open(‘Student.dat’,’rb’)
total=0
pending=0
try:
while True:
if R==1000:
……………
total=total+R
if R>0:
pending=pending+R
except:
f.close()
print(“Total Amount due is “,total-pending)
Total_Amount()
When the Total_Marks() function is invoked, the output displayed is
Total Amount due is 200
Identify the appropriate jump statement from the following to obtain the above output.
(a) continue
(b) break
(c) pass
(d) return

C

Question. Consider the statements given below:
Fileobj = open(“Report.txt”, ‘r’)
Fileobj.seek(25,0)
Choose the statement that best explains the second statement.
(a) It will place the pointer at 25 bytes ahead of the current file pointer position.
(b) It will place the pointer at 25 bytes behind from the end-of file.
(c) It will place the pointer at 25 bytes from the beginning of the file.
(d) It returns 25 characters from the 0th index.

C

Question. Given a tuple Tup1=(25,35,43,22,13,56,45,78,90) Identify the statement from the list below that will produce the result as (25,43,13,45,90)
(a) print(Tup1[::])
(b) print(Tup1[0:9:1])
(c) print(Tup1[::2])
(d) print(Tup1[2:0:9])

C

Question. Identify the incorrect statement regarding passing parameters to functions.
(a) You can pass keyword arguments in any order.
(b) You can pass positional argument in any order.
(c) You can pass both positional and keyword arguments together.
(d) An argument list must have any positional arguments followed by any keyword arguments.

B

Question. In which mode are Python instructions stored in a file with .py extension?
(a) Script mode
(b) Run mode
(c) Interactive mode
(d) All of these

A

Question. Consider a function
def Cal_cube(n):
Which of the following function call can be used to invoke the given function definition?
(a) Calc_cube(5):
(b) Calc_cube()
(c) Calc_cube(5)
(d) Calc_cube(5,5,5)

C

Question. Which of the following options can be used to read the first five characters of a text file ‘Poem.txt’ from the file object File1?

C

Question. Which of the following functions forces the writing of data on disc which is still pending in the output buffer?
(b) save()
(c) flush()

C

Question. Which of the following statements is considered as multiline comment?
(a) /* Program to calculate Simple Interest. */
(b) #Program to calculate
Simple Interest
(c) ’’’Program to calculate
Simple Interest ’’’
(d) // Program to calculate
Simple Interest //

C

Question. Which of the following groups of functions belongs to CSV module?

A

Question. Consider the statements given below:
import pickle
colors=[‘Red’,‘Green’,‘Orange’,‘Yellow’,‘Blue’]
with open(‘Mycolors.dat’,‘wb’) as mybinfile:
——————— #Statement1
Identify the missing code in Statement 1 that will write data from a list on the binary file.
(b) pickle.dump(mybinfile, colors)
(c) pickle.dump(colors, mybinfile)

C

Question. Consider the following directory structure:

There are three directories under root directory ‘Admin’. The current working directory is Final. Identify
the relative path name for file ‘Result1.xlsx’.
(a) .\Result1.xlsx
(c) ..\First Term\Result1.xlsx
(d) First Term\Result1.xlsx

C

Question. Consider a file “myrhymes.txt”
If you’re happy and you know it, clap your hands (clap clap)
If you’re happy and you know it, clap your hands (clap clap)
If you’re happy and you know it, and you really want to show it.
If you’re happy and you know it, clap your hands (clap clap)
What will be the output of the following code?
fileobj=open(‘myrhymes.txt’,’r’)
count = 0
word= l.split()
for i in word:
if(i==’clap’):
count=count+1
print(count)
fileobj.close()
(a) 9
(b) 6
(c) 3
(d) 4

C

Question. In Python, the terms ‘global’, ‘else’ and ‘pass’ are used to refer to:
(a) Literals
(b) Keywords
(c) Variables
(d) Punctuators

B

Question. Identify the output of the following Python statements.
for i in range(10):
if i==5:
continue
print(i,end=’’)
(a) 0123456789
(b) 012346789
(c) 123456789
(d) 12346789

B

Question. Identify the incorrect statement regarding declaration of default parameters in function header.
(a) def Total_Amt(cost = 200, qty,disc= 0.2):
(b) def Total_Amt(cost= 200, qty=20, disc):
(c) def Total_Amt(cost, qty=20,disc=0.2):
(d) def Total_Amt(cost, qty=20, disc):
(a) Only (b)
(b) Both (b) and (c)
(c) Both (a) and (c)
(d) Both (b) and (d)

D

(a) A list of integers
(b) String
(c) A list of single characters
(d) A list of strings

D

Question. What will be the output of the following Python code?
def FinalMarks(T1, T2):
return T1+T2
T1=150
T2=160
print(”Total marks scored are”,FinalMarks())
(a) 310
(b) 0
(c) None
(d) Error

D

Question. Identify the statement that results in an error.
(a) Dict1 = {‘Cost’:120, ‘Qty’:10, ‘Amount’: 120}
(b) Dict1 = {‘RollNo’ : 1, ‘Name’: ‘Shilpa’, ‘Marks’ : 90}
(c) Dict1= (‘Marks1’: 80, ‘Marks2’: 90, ‘Marks3’: 96)
(d) Dict1= { }

C

Question. What will be the output of the following code?
number1 = 100
def funct1(x):
global number1
number1 = 200
number1 = number1**x
print(number1)
funct1(2)
print(number1)
(a) 200/40000
(b) 100 / 10000
(c) 100 / 40000
(d) 200 / 10000

C

Question. Take these numbers into consideration: 2,5,6,3,5,2,1,7. Write a command that declares a tuple named A with these integers as elements.
(a) A = (2,5,6,3,5,2,1,7)
(b) A = 2,5,6,3,5,2,1,7
(c) A = {2,5,6,3,5,2,1,7}
(d) A = [2,5,6,3,5,2,1,7]

A

Question. What is the output of the following code snippet?
def flipnumber(L,y):
for i in range(y):
if L[i]%3==0:
L[i]**=3
if L[i]%2==0:
L[i]**=2
L=[3,2,4,8,9]
flipnumber(L,5)
for i in L:
print(i,end=’#’)
(a) 9#2#8#16#81#
(b) 27#4#16#64#729#
(c) 9#8#16#64#729#
(d) 27#8#16#81#729#

B

Question. Identify the output of the following Python statements.
L1= [[‘Red’,’Green’],[‘Blue’,‘Yellow’,‘Orange’],
[‘Black’,‘White’]]
print(L1)
(a) ‘c’
(b) ‘a’
(c) Black
(d) White

A

Question. Consider a file ‘quote.txt’
If you’ll look at what you have in life,
you’ll always have more.
If you look at what you don’t have in life,
You’ll never have enough.
What will be the output of the following code?
fileobj = open(“quote.txt”, ‘r’)
print(R1)
print(R4)
(a) 9 /you’ll never
(b) 37 / have enough.
(c) 9 / If you look
(d) 27 / you’ll never

A

Question. Evaluate the following expression and identify the correct answer:
(24 * 3) – 2 % 4 + 8 // 3 + 3**4
(a) – 9
(b) 153
(c) 70
(d) 152

B

Question. What is the correct declaration of a tuple P to obtain the following output?
p = …………………
print(p*2)
Output: (240, 240)
(a) (240)
(b) “240”
(c) (240,)
(d) (120)

C

Question. Suppose content of ‘mytext.txt’ file is:
The key to success is to focus on goals, not obstacles.
What will be the output of the following code?
file = open(“mytext.txt”, ‘r’)
(a) The key to
(b) obstacles.
(c) Error
(d) No Output

D

Question. What will be the output of the following code?
import random
color = [‘Red’, ‘Orange’, ‘Yellow’, ‘Black’, ‘Cyan’]
for c in range(len(color)):
p = random.randint(2,4)
print(color[p],end=’\$’)
(a) Red\$Red\$Cyan\$Orange\$Yellow\$
(b) Cyan\$Black\$Black\$Cyan\$Yellow\$
(c) Black\$Red\$Black\$Red\$Black\$
(d) Black\$Orange\$Yellow\$Black\$Black\$

B

Question. What will be the output of the following code?
def simple_interest(p,r,t=2):
return p *r*t
SI= simple_interest(10000,0.2)
print(SI,simple_interest(50000,0.3,3))
(a) 45000.0 45000.0
(b) 45000.0 4000
(c) 4000.0 45000.0
(d) 4000.0 4000.0

C

Question. Suppose the content of ‘moral.txt’ is:
Sometimes we’re tested not to show our weaknesses but to discover our strengths.
What will be the output of the following code?
file = open(“moral.txt”)
word = line.split()
for w in word:
if len(w)>8:
print(w)
file.close()
(a) Sometimes/weaknesses/discover/strengths
(b) sometimes/tested/weaknesses/strengths
(c) sometimes/weaknesses/strengths
(d) tested/show/our/but

C

Question. Identify the output of the following Python statements.
x=200
while x>10:
if x%2==0:
z=x//2
else:
z=x**2
print(z)
x=x-50
(a) 100 / 75/50/25
(b) 100 / 50/25/10
(c) 400 / 200 / 100 /50
(d) 100 / 22500 / 2500/ 625

A

Case Study Based Questions

Rashi is learning Python in preparation for an internship exam. She is having a problem with one question in which she has been assigned an incomplete Python code (given below) to create a CSV file called ‘Employee.csv.’ Assist her in completing the code that generates the CSV file with the given content.
Employee.csv
Empno,Name,Desig,Salary
E1,Bharti,Sales,30000
E2,Anuj,Marketing,50000
E3,Mudit,Accounts,64000
Incomplete Code:______
Csvfile = open(______, _______, newline=’’)
CsvObj = csv. ________( ________) #Statement 3
Rows = []
Fields = [‘Empnumber’, ‘EmpName’, ‘EmpDesig’, ‘EmpSalary’]
Rows.append(Fields)
for i in range(5):
Empno = input(“Enter Employee No:”)
Name = input(“Enter Employee Name:”)
Desig = input(“Enter Designation:”)
Salary = int(input(“Enter Salary:”))
records= [________________]
Rows.________(______)
_______._______(Rows)
Csvfile.close()

Question. 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”

A

Question. Identify the missing code for the blank space in line marked as Statement 2.
(a) “Employee.txt”, ‘rb’
(b) “Employee.csv”, ’wb’
(c) “Employee.csv”, ’w’
(d) “Employee.dat”, ’w’

C

Question. Identify the suitable code for blank space in the line marked as Statement 5.
(a) insert(data)
(b) delete(data)
(c) append(records)

C

Question. Identify the suitable code for blank space in the line marked as Statement 6.
(b) CsvObj.dumprow()
(d) CsvObj.writerows()

D

Question. Choose the function name (with argument) that should be used in the blank space of line marked as Statement 3.
(a) writer(“Employee.csv”)
(c) writer(CsvObj)
(d) writer(Csvfile)