0% found this document useful (0 votes)
10 views9 pages

MS - Hy Cs Xii2023

The document is a question paper for the Half Yearly Examination in Computer Science for Class XII at Kendriya Vidyalaya No 1, Jalahalli, Bengaluru. It includes multiple-choice questions, assertion and reasoning questions, fill-in-the-blanks, programming tasks, and theoretical questions covering various topics in Python and computer science concepts. The exam assesses students' understanding of Python programming, file handling, data structures, and networking protocols.

Uploaded by

mayank.aiml24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

MS - Hy Cs Xii2023

The document is a question paper for the Half Yearly Examination in Computer Science for Class XII at Kendriya Vidyalaya No 1, Jalahalli, Bengaluru. It includes multiple-choice questions, assertion and reasoning questions, fill-in-the-blanks, programming tasks, and theoretical questions covering various topics in Python and computer science concepts. The exam assesses students' understanding of Python programming, file handling, data structures, and networking protocols.

Uploaded by

mayank.aiml24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

KENDRIYA VIDYALAYA NO 1 JALAHALLI WEST BENGALURU

HALF YEARLY EXAMINATION – 2023


COMPUTER SCIENCE – XII (SET-1)
SECTION - A
1 Which among the following keywords is also an operator? 1
a) True b) is c) for d) break
An b) is
s
2 What will be the output of the python operation - 10 and 5 or 10 1
a) 10 b) 5 c) True d) False
An b) 5
s
3 What will be the output of the following python program? 1
s = "mandolinmaniac"
print(s.split("man"))
a) ['', 'dolin', 'iac']
b) ['man', 'dolin', 'man','iac']
c) ['dolin', 'iac']
d) ['dolin', 'man','iac']

An a) ['', 'dolin', 'iac']


s
4 Which of the following python functions returns the value for a key of a dictionary? 1
a) popitem() b) remove() c) pop() d) del

An b) pop()
s
5 Which of the following python function header declaration is wrong? 1
a) def myfunction(x, y, z):
b) def myfunction(x, y=10, z=20):
c) def myfunction():
d) def myfunction(x=10, y, z=20):
An d) def myfunction(x=10, y, z=20):
s
6 When a python function returns more than one value in a single return statement, which of the 1
following collection objects gets returned?
a) List b) Tuple c) Dictionary d) String
An b) Tuple
s
7 Which type of exception will be raised for the operation print('A'+10) 1
a) ValueError
b) TypeError
c) KeyError
d) NameError
An b) TypeError
s
8 Which of the following modes will allow the file to be opened for only writing? 1
a) 'a+'
b) 'r+'
c) Both option a) and b)
d) Neither option a) nor option b)
An d) Neither option a) nor option b)
s
9 Consider a file 'string.txt' has some characters written into it. Now the file is opened in 'rb' mode using 1
the file object myfile. What will be the output of the following python operation?
myfile.read(4)
myfile.seek(5,1)
myfile.read(2)
myfile.seek(-4,1)
print(myfile.tell())
a) 8 b) 7 c) 6 d) Error
An b) 7
s
10 Which of the following network devices is used to connect between two dissimilar protocols? 1
a) Switch b) Router c) Modem d) Gateway
An d) Gateway
s
11 Which network protocol provides a command line interface for communication with a remote device or 1
server?
a) Telnet b) HTTP c) PPP d) SMTP

An a) Telnet
s
12 Which of the following switching techniques sends small pieces of data across a network? 1
a) Circuit switching
b) Message switching
c) Packet switching
d) All the above.
An c) Packet Switching
s
13 Which of the following is false for XML? 1
a) XML is a case sensitive language.
b) XML is used to describe data for a webpage.
c) XML has fixed set of tags.
d) XML can be used as a meta language.
An c) XML has fixed set of Tags.
s
14 Which of the following protocols is used to receive emails? 1
a) POP3 b) SMTP c) FTP d) TCP
An a) POP3
s
Questions 15 to 18 are ASSERTION AND REASONING based questions. Mark the correct choice
as:
i) Both A and R are true and R is the correct explanation for A
ii) Both A and R are true and R is not the correct explanation for A
iii) A is True but R is False
iv) A is false but R is True

15 Assertion: Python interactive mode allows to execute one statement/expression at a time. 1


Reasoning: The Python shell is useful for executing simple programs or for debugging parts of complex
programs.
An i) Both A and R are true and R is the correct explanation for A
s
16 Assertion: Positional parameters in a python function must always follow the default parameters. 1
Reasoning: Default parameters provide a default value whenever the argument is not passed during a
function call.
An iv) A is False but R is True
s
17 Assertion: Text files can only store objects as strings in them. 1
Reasoning: Text files can be opened in text as well as binary modes.
18 ii) Both A and R are true and R is not the correct explanation for A
18 Assertion: CSV files stores data in a file with values separated by commas and we can open them 1
normally using open() function.
Reasoning: CSV files are simple text files with .csv extension.
An i) Both A and R are true and R is the correct explanation for A
s
SECTION-B
19 State True or False: 2
a) Nested lists inside a tuple are mutable. Eg. (10, [20,30,40], 50) can become (10, [20,50,40], 50)
b) A python user defined function may not have a body at all and can be successfully called. Eg.
def foo():

foo() #function call


An a) True b) False
s
20 Fill in the blanks: 2
a) The return datatype of readline() function in python is ________.
b) The block that is not mandatory in try: except: and finally: is __________.
An a) String b) finally
s
21 Amaya has created a python program and wants to permanently modify an integer variable, declared 2
outside the function, by the user defined function. He has written the following code, but he is unable
to get the desired result. Help him to identify his mistake and re-write the program to get the desired
result. Also suggest to him the correct output of the program.
def change():
a = a+10
a = 20
change()
print(a) # the variable a should be permanently modified.
An Amaya should write global a as the first statement in the function definition. The output is 30.
s def change():
global a
a = a+10
a = 20
change()
print(a)
22 Read the following programs and name the exceptions that will arise after executing the code: 2
a) print(int('A'))
b) a = 10
print(b)
An a) ValueError b) NameError
s
23 What will be the lowest and the highest values of n in the program given below. Also predict the correct 2
output from the given choices:
import random
name = ['TOM','BOB','JIM','SID','JOE']
low = 1
high = 4
for i in range(4):
n = random.randrange(low, high+1)
print(name[n], end='#')
a) BOB#JOE#JIM#BOB#
b) JIM#JIM#BOB#SID#
c) BOB#JIM#JIM#BOB#
d) JOE#SID#SID#BOB#
An Lowest value of n – 1
s Highest value of n – 4
c) BOB#JIM#JIM#BOB#

24 Rewrite the following program after removing the errors. Also underline the corrections made. 2
n = int(input())
if n % 10 = 0:
n = n + 10
elif n >= 20:
n =- 5
else
n = 40
print("n=" n)
An n = int(input())
s if n % 10 == 0:
n = n + 10
elif n >= 20:
n -= 5
else:
n = 40
print("n=", n)
25 Write one advantage and one disadvantage of bus topology. 2
An Advantage: Less cable requirement
s Disadvantage: Network stops or gets segmented if the backbone cable breaks.
Or any other advantage and disadvantage.
26 Expand the following abbreviations: 2
a) SMTP
b) ARPANET
An a) Simple Mail Transfer Protocol
s b) Advanced Research Project Agency Network
SECTION – C
27 Fill in the blanks for the following questions: 3
a) ___________ topology is highly dependent on the central node.
b) The unit of measurement of data transfer rate is ____________.
c) The relative address of a document or a resource on a webserver is called ___________.
An a) Star b) baud or bits per sec c) URL
s
28 Predict the output of the following python program: 3
def changeme(a,b=10):
global c
a += b
b += c
c=a+b
print(a, b, c)
return b//2
a,b,c= 5,20,15
b = changeme(a,c)
print(a,b,c)
An 20 30 50
s 5 15 50
(1/2 marks for each correct option)
29 What will be the output of the following python program: 3
data = [10, 20, 30, [40,50,60],70]
x = data.pop(3)
print(x)
data[2:2]=[40,50]
print(data[4])
print(len(data))
An [40, 50, 60]
s 30
6
[OR]
What will be the output of the following python program:
name = "HOME ALONE WITH MOM"
data = name.partition('ALONE')
print(data[0].lower())
print(data[2].title())
print(data[1][::-2])
An home
s With Mom
EOA
30 A pre-written text file data.txt has some strings stored in it. Write a python function display() that reads 3
the contents of the file and displays all the words that start with the substring 'th' or 'Th'.
Eg. If the file has the following data:
“There was a man who throughout his life
thanked others for their little help”
The output should be:
There
throughout
thanked
[OR]
A pre-written text file info.txt has some strings written in it. Write a python function countme() that
reads the contents of the file and returns the count of all the words which are 'that'.
An def display():
s f = open('data.txt', 'r')
s = f.read()
l = s.split()
for x in l:
if x.startswith('th') or x.startswith('Th'):
print(x)
f.close()
[OR]
def countme():
count=0
f = open(info.txt', 'r')
s = f.read()
l = s.split()
for x in l:
if x == 'that':
count+=1
f.close()
return count
31 A pre-written text file info.txt has some lines written in it. Write a function display() that prints all the 3
lines that has the word 'India' in them.
[OR]
A pre-written text file data.txt has some lines written in it. Write a function display() that prints all the
lines that have exactly 10 words in them.
An def display():
s f = open('info.txt', 'r')
for line in f:
if 'India' in line:
print(line)
f.close()
[OR]
def display():
f = open('data.txt', 'r')
for line in f:
l = line.split()
if len(l)==10:
print(line)
f.close()
32 a) Mention two differences between a hub and a switch. (2) 3
b) Give one example of a popular web browser. (1)

An a) One mark for each difference


s b) One mark for a correct example
SECTION – D
33 A binary file student.dat needs to be written with the following data in the form of dictionaries. 4
Rollno Name Class Marks
1001 Tom 10 75
1002 Bob 11 80
1003 Sid 10 90
a) Write a python function insert() that opens the binary file for writing and writes all the three
records in it.
b) Write python function view() that opens the binary file for reading and displays student details
whose Marks are more than 75.
[OR]
A binary file emp.dat needs to be written with the following data in the form of lists.
Empno Ename Gende Salary
r
2001 Richa F 7500
2002 Sonam F 9000
2003 Manu M 8000
a) Write a python function insert() that opens the binary file for writing and writes all the three
records in it.
b) Write python function show() that opens the binary file for reading and displays employee details
whose gender is F.
An import pickle
s def insert():
f = open('student.dat', 'wb')
d1 = {'Rollno':1001, 'Name': 'Tom', 'Class':10, 'Marks':75}
d2 = {'Rollno':1002, 'Name': 'Bob', 'Class':11, 'Marks':80}
d3 = {'Rollno':1003, 'Name': 'Sid', 'Class':10, 'Marks':90}
pickle.dump(d1,f)
pickle.dump(d2,f)
pickle.dump(d3,f)
f.close()
def view():
f = open('student.dat', 'rb')
while True:
try:
d = pickle.load(f)
if d['Marks']>75:
print(d)
except EOFError:
break
f.close()
2 marks each for the two functions. Marks should be deducted based on syntax, indentation, and logical
errors. The OR part is similar hence not elaborated.
34 Write a python function push(stack) that pushes on to an empty list(stack) all the values of a dictionary 4
whose keys are palindromes.
Eg: for the dictionary {'ROY':100, 'ARORA':200, 'MADAM':250, 'SAHA':300, 'LEVEL':400} the stack should
have the values 200, 250 and 400 since ARORA, MADAM and LEVEL are palindromes.
Write a python function popstack(stack) that pops out the last added element from the stack each time
the function is called and also prints a 'Stack Empty' message if all the elements have popped out.
Also write the call statements for both the functions.
[OR]
Write a python function push(stack) that pushes on to an empty list(stack) all the values from a list of
strings, whose lengths are more than 5.

Write a python function popstack(stack) that pops out the last added element from the stack each time
the function is called and also prints a 'Stack Empty' message if all the elements have popped out.
Also write the call statements for both the functions.
An def push(stack):
s data = {'ROY':100, 'ARORA':200, 'MADAM':250, 'SAHA':300, 'LEVEL':400}
for x in data:
if x==x[::-1]:
stack.append(data[x])

def popstack(stack):
if len(stack)==0:
return 'Stack Empty'
else:
return stack.pop()
stack=[]
push(stack)
print(popstack(stack))
4 marks for the correct code. Marks should be deducted based on syntax, indentation, and logical
errors.
[OR]
def push(stack):
data = ['ROYAL', 'ARMSTRONG', 'MADAM', 'PYTHON', 'ANACONDA']
for x in data:
if len(x)>5:
stack.append(x)

def popstack(stack):
if len(stack)==0:
return 'Stack Empty'
else:
return stack.pop()
stack=[]
push(stack)
print(popstack(stack))

SECTION – E
35 Rohit wants to create a python application that writes a set of records in a csv file info.csv. He is having 5
some issues and has left a few blank lines. On behalf of Rohit, you are directed to write the missing
codes.
_____________ # Statement 1
f = open('info.csv', 'w', newline='')
csvwriter = __________________ # Statement 2
head = ['Id', 'Book', 'Quantity', 'Price']
data = [[101, 'Stardust', 100, 50], [102, 'Athabasca', 200, 300], [103, 'Troy', 150, 180]]
___________________ # Statement 3
___________________ # Statement 4
___________________ # Statement 5

a) Statement 1 : Write a statement that enables python to work with csv files.
b) Statement 2 : Write a statement to initialize the csvwriter object.
c) Statement 3 : Write a statement to write the head object to the file.
d) Statement 4 : Write a statement to write the data object to the file.
e) Statement 5 : Write a statement to end the program be releasing the file handle f.
a) Statement 1 : import csv
b) Statement 2 : csv.writer(f)
c) Statement 3 : csvwriter.writerow(head)
d) Statement 4 : csvwriter.writerows(data)
e) Statement 5 : f.close()
36 Tribor infotech has their new campus in Bangalore. They have four buildings on their campus that need 5
to be connected through a network. The details of the number of computers in each building and
distance between the buildings are as below.

Accoun
HR
ts

Tech Admin

Building Computers Buildings Distance


Accounts 150 Accounts - HR 75m
HR 100 Accounts – Tech 90m
Tech 75 Accounts - Admin 150m
Admin 300 HR – Tech 200m
HR – Admin 60m
Tech - Admin 80m
Answer the following questions based on the above case study:
a) Suggest the placement of the server on the campus with Justification to do so.
b) Draw a suitable cable layout to connect all the buildings in a local area network.
c) Suggest the placement of Switches and Repeaters on the campus.
d) Suggest the high speed wired communication line between Bangalore campus to Mysure Office.
e) Suggest the protocol be used to connect to the ISP through a conventional telephone line from
the campus.

An a) Admin building, since it has maximum number of PCs.


s b)

Account
HR
s

Tech Admin

c) Switches in all the buildings and Repeater between Admin and Accounts building
d) OFC
e) PPP

You might also like