Cs SQP 5.1
Cs SQP 5.1
(a) Binary files 15. Which of the following functions will read lines of
a text file as list elements.
10. In the following code, which lines will give error? (a) read( )
(Assume the lines are numbered starting from 1.)
(b) get()
mul=3
value=10 (c) readline( )
for i in range (1, 6, 1): (d) readlines( )
if (value % mul = 0): Sol :
print (value * multiply)
else (d) readlines( )
print (value + multiply)
16. Which of the following will be the output of the
(a) 4,5
statement given below?
(b) 4,5,6
print([12,34,56,78,90].pop())
(c) 4,5,6,7
(a) 78 (b) 90
(d) No errors
(c) 12 (d) 12,34,56,78,90
Sol :
Sol :
(c) 4,5,6,7
(b) 90
11. There can be____foreign keys in a relation.
Direction (Q.Nos. 17-18) are Assertion and
(a) 2 (b) 3
Reason based questions.
(c) 1 (d) Multiple
Sol : 17. Assertion (A) In a cross join the number of records
in the output will be the maximum.
(d) Multiple
Reason (R) A cross join is also called a Cartesian
12. The_____clause with the COUNT() function product.
counts only the unique values in an attribute. (a) Both A and R are true and R is the correct
(a) UNIQUE explanation for A.
(b) HAVING (b) Both A and R are true but R is not the
(c) DISTINCT correct explanation for A.
(d) LIKE (c) A is true but R is false.
Sol : (d) A is false but R is true.
(c) DISTINCT Sol :
13. User can write Python script using (b) Both A and R are true but R is not the correct
(a) MySQL.connector library explanation for A.
(b) SQL.connect library 18. Assertion (A) A file that is opened using the
(c) MySQL.connect library open() function may not specify the mode of
opening it.
(d) None of these Reason (R) If the mode is not specified , the read
mode is used by default..
Sol :
(a) Both A and R are true and R is the correct
(a) MySQL.connector library explanation for A.
14. _____is a protocol used for remote login. (b) Both A and R are true but R is not the
(a) HTIT correct explanation for A.
(b) PPP (c) A is true but R is false.
(c) IRCP (d) A is false but R is true.
(d) Telnet
Sol :
Sol :
(b) Both A and R are true but R is not the correct
(d) Telnet explanation for A.
Page 3 Sample Paper 1 Computer Science Class 12
Write a program to read the content from a text ND50 T Prasad 122-K, SDA New Delhi
file status.txt, count and display the total
number of lines and blank spaces present in it. TABLE: RECIPIENT
e.g. if the status.txt file contains the following
RecID SenderlD RecName RecAddress RecCity
lines:
Welcome to your one-step solutions for all your KO05 ND01 R Bajpayee 5, Central Kolkata
Avenue
study, practice and assessment needs for various
competitive & recruitment examinations and ND08 MU02 S Mahajan 116, A Vihar New
Delhi
school segment. We have been working tirelessly
for over a decade to make sure that you have MU19 ND01 H Singh 2A, Andheri Mumbai
East
best in class study resources because you deserve
SUCCESS AND NOTHING LESS... MU32 MU15 P K Swamy B5, C S Mumbai
Terminus
The output will be:
The status file contents are ND48 ND50 S Tripathi 13, B1 D, New
Mayur Delhi
Total lines in file are: 4 Vihar
Total spaces in file are: 43
(i) To display the names of all Senders from
Sol : Mumbai.
import os (ii) To display the RecID, SenderName,
tfile=‘status.txt’ SenderAddress, RecName, RecAddress
if os.path.isfile(tfile): for every Recipient.
fob=open(tfile, ‘r’) (iii) To display Recipient details in ascending
blankspaces=total_lines=0 order of RecName.
print(“The status file contents (iv) To display number of Recipients from
are”). each City.
print(“_____”) (b) Display the Sender name and corresponding
while True: Recipient name from the tables where sender
aline=fob.readline() is from NEW DELHI and recipient is from
if not aline: KOLKATA.
break Sol :
else:
(a) (i) SELECT SenderName FROM SENDER
total_lines=total_lines+1
WHERE SenderCity = ‘Mumbai’;
aline=aline.rstrip()
(ii) SELECT RecID, SenderName,
for i in aline:
SenderAddress, RecName,
if i.isspace():
RecAddress
blankspaces=blankspaces+1
FROM RECIPIENT, SENDER WHERE
print(“Total lines in file are:
RECIPIENT.SenderlD = SENDER.
%d” %total_lines)
SenderID;
print(“Total space in file are:
(iii) SELECT *FROM RECIPIENT ORDER
%d” % blankspaces)
BY RecName;
fob.close()
(iv) SELECT COUNT(*) AS “No. of
else:
Recipients”, RecCity FROM
print(“File does not exist”)
RECIPIENT GROUP BY RecCity;
28. (a) Consider the following tables SENDER and (b) SELECT SenderName, RecName
RECIPINT. Write SQL commands for the FROM Sender S , Recipient R
statements (i) to (iv). WHERE S.SenderlD=R.SenderID AND
(SenderCity= “New Delhi” AND
TABLE: SENDER RecCity=“KOLKATA”);
SenderlD SenderName SenderAddress SenderCity
29. Write a user defined function change(L) to accept
ND01 R Jain 2, ABC Appts New Delhi
a list of numbers and replace the numbers in the
MU02 H Sinha 12, Newtown Mumbai
list with their sum of digits.
MU15 S Jha 27/A, Park Street Mumbai Example
Page 6 Sample Paper 1 Computer Science Class 12
Input : [32,142,215,26,7]
Output : [5, 7 , 8 , 8, 8,7]
Sol :
L= [ ]
n=int(input(“Enter number of
element”))
for i in range (1, n+1):
b=int(input(“Enter element:”))
L=append(b)
i=0
for a in L:
s=0 Section D
while a>0:
s+=a%10 31. Freshminds University of India is starting its first
a//=10 campus in Ana Nagar of South India with its
L[i]=s centre admission office in Kolkata. The university
i+=1 has three major blocks comprising of Office block,
print(L) Science block and Commerce block is in 5 km area
campus.
30. Write Push (contents) and Pop() methods in
As a network expert, you need to suggest the
Python to add numbers and remove numbers
network plan as per (i) to (v) to the authorities
considering them to act as Push and Pop
keeping in mind the distance and other given
operations of stack.
parameters.
Sol :
def Push (contents):
if(len(stack) >= limit):
print(“Stack Overflow!”)
else :
stack.append (contents)
print (“Stack after Push”, stack)
def Pop( ):
if (len (stack) <= 0):
print(“Stack Underflow!”) Expected wire distance between various locations.
return 0 Office Block to Science Block 90 m
else : Office Block to Commerce Block 80 m
return stack.Pop( )
Science Block to Commerce Block 15 m
or
Kolkata Admission Office to Ana Nagar 450 km
Find the final contents of a stack on which the
Campus
following operations are done.
Expected number of computers to be installed at
1. Push(100)
various locations in the university are as follows:
2. Push(200)
Office Block 10
3. Push(50)
Science Block 140
4. Push(50) Commerce Block 30
5. Pop() Kolkata Admission Office 8
6. Push() (i) Suggest the authorities, the cable layout
7. Pop(2) amongst various blocks inside university
campus for connecting the blocks.
8. Pop() (ii) Suggest the most suitable place (i.e. block)
to house the server for this university with a
Sol :
suitable reason.
Page 7 Sample Paper 1 Computer Science Class 12
w1 = csv.writer(f2)
It produces the output, It does not produce
for row in r1 :
but undesired. any output.
w1.writerow(row)
e.g. in place of e.g. in place of f1.close()
(c = a * b); if by (a == b); if by mistake f2.close()
mistake (a == b); is written, it def convertcsv():
(c = a + b); is written, will be a syntax error. f1 = open(“old.csv”,‘r’)
it will be a logical f2 = open(“converted.csv”, ‘w’,
error. newline = “\n”)
(b) fetchone() returns the next row from the r1 = csv.reader(f1, delimiter =
result set as tuple. If there are no more rows “:”)
to retrieve, None is returned. w1 = csv.writer(f2, delimiter =
e.g. To fetch only one record “;”)
import mysql.connector for row in r1:
con = mysql.connector.connect w1.writerow(row)
(host = “localhost”, f1.close()
user = “root”, f2.close()
passwd = “arihant”,database addcsv()
= “PythonDB”) convertcsv()
cursor = con.cursor() or
try: CSV files are opened with which argument
cursor.execute(“Select Name, to suppress EOL translation. Write a python
RollNo, Address, Percentage from program to perform the following using functions
Student”) as follows :
display = cursor.fetchone() (a) copytocsv() :
print(display) A CSV file marks.csv has name, class and
except: marks separated by comma. Write the Python
con.rollback() function to copy only the name and class to
con.close() another CSV file class.csv.
(b) copyselected() :
33. Which module is used to operate on CSV file? The CSV file marks.csv which has name,
Write a python program with following functions class and marks separated by comma. Write
: the Python function to copy only rows of
(a) addcsv(): students of class 2 to another CSV file class.
File old.csv has come from branch in Pune csv.
and it needs to be added to file updated.
csv which has data for all branches. Write Sol :
the code in the function to perform the same. newline=
(b) convertcsv() : Program:
A file old.csv has come with separator : but import csv
your system can only read ; Write a program def copytocsv():
to convert to converted.csv file. Write the file = open(‘class.csv’,‘w’,
function to change the separator of the file. newline=“ ”)
Sol : writer = csv.writer(file)
with open(‘marks.csv’) as csvfile:
To read and write in CSV files we need to import data = csv.reader(csvfile)
csv module. for row in data:
Program: writer.writeraw(row[0],
import csv row[1]])
def addcsv(): file.close()
f1 = open(“old.csv”, ‘r’) def copyselected():
f2 = open(“updated.csv”, ‘a’, file = open(‘class.csv’, ‘w’,
newline = “\n”) newline= “\n”)
r1 = csv.reader(f1) w1 = csv.writer(file)
Page 9 Sample Paper 1 Computer Science Class 12
35. The code given below reads a text file and displays
those words that begin with an uppercase vowel
and end with a lowercase vowel . Some of the codes
are missing .Write codes to fill up the blanks.
f=open(“emp.txt”)
filedata=f.read()
count=0