Professional Documents
Culture Documents
E-mail or Electronic A chat is a kind of 23. (a) Write the full forms of
mail is a system where application that needs (i) URL
the recipient may not both the users to be (ii) VoIP
be online. online in real time. (b) Write the use of SMTP.
Sol :
The sender writes an Each writes a message
(a) (i) URL Uniform Resource Locator
E-mail address, subject and sends it to other.
and the message along On the other side (ii) VoIP Voice over Internet Protocol
with any attachment the receiver reads (b) SMTP (Simple Mail Transfer Protocol) is
files and sends. the message and a protocol used for sending and receiving
accordingly answers. emails.
or
24. Find the output of following code.
How are LAN and MAN different? dic = {“Nitin” : (21, “NIIT”), “Ankit”
Sol : : (15, “NIIT”)}
print(“The original dictionary : ”,
LAN (Local Area Network) is a kind of network of str(dic))
computers within a local area like a room, campus result= [(key, i, j) for key, (i, j)
, building etc. The computers may be connected in dic.items()]
by wires or wireless mediums . Distance is roughly print(“The list after conversion :
500 m 1 km. MAN (Metropolitan Area Network) ”, str(result))
is a kind of network of computers spread across a
city. The range is roughly the diameter of a city Sol :
60 Km . CATTV is an example of MAN. The original dictionary : {‘Ankit’ : (15,
‘NIIT’), ‘Nitin’ : (21, ‘NIIT’)}
Page 4 Sample Paper 1 Computer Science Class 12
Sol :
(b) Write the output for SQL queries (i) to (iv),
DROP A DDL command is used to remove a table
which are based on the table ITEMS.
or a database. The DROP command removes the
entire table with its structure and records. TABLE: ITEMS
DELETE A DML command is used to delete Code IName Qty Price Company TCode
records of a table. 1001 DIGITAL 120 11000 XENITA T01
or PAD 12i
Identify any two DML commands from the 1006 LED 70 38000 SANTORA T02
following and also explain. SCREEN
ALTER , INSERT , UPDATE , DROP , CREATE 40
print(“U :”.u)
NAME STRNAME
f.close()
Amit SCIENCE + COMP or
Arjun SCIENCE + ECO Write a Python program to find the longest word
in file status.txt. If contents of status.txt are
Zaheer SCIENCE + BIO Welcome to your one-step solutions for all your
(b) (i) study, practice and assessment need for various
MAX(Price) MIN(Price) competitive and recruitment examinations and
school segment. We have been working tirelessly
38000 1200
for over a decade to make sure that you have
(ii)
best in class study resources because you deserve
AMOUNT SUCCESS AND NOTHING LESS...
107500 Output should be
(iii) Longest word : examinations
TCode Sol :
T01 def Longest():
f=open(“status.txt”)
T02
words=f.read().split()
T03 max_len=len(max(words, key=len))
(iv) for word in words:
MAX (Company) if(len(word)==max_len):
print(“Longest word:”,word)
XENITA
27. Write a function countEU() in Python, which 28. (a) Consider the following tables GARMENT
should read each character of a text file. IMP. and FABRIC. Write SQL commands for the
TXT should count and display the occurrence of statements (i) to (iv).
alphabets E and U (including small cases e and
TABLE: GARMENT
u too).
e.g. If the file content is as follows : GCODE DESCRI- PRICE FCODE READY-
PTION DATE
Pinaky has gone to his friends house.
His friends name is Ravya. Her house is 12 km 10023 PENCIL 1150 F03 19-DEC-08
SKIRT
from Pinakys house.
The countEU() function should display the 10001 FORMAL 1250 F01 12-JAN-08
SHIRT
output as
E:8 10012 INFORMAL 1550 F02 06-JUN-08
SHIRT
U:3
10024 BABY TOP 750 F03 07-APR-07
Sol :
10090 TULIP 850 F02 31-MAR-07
def countEU(): SKIRT
f=open(“IMP.TXT”) 10019 EVENING 850 F03 06-JUN-08
e=0 GOWN
u=0 10009 INFORMAL 1500 F02 20-OCT-08
while True: PANT
l=f.readline() 10007 FORMAL 1350 F01 09-MAR-08
if not l: PANT
break 10020 FROCK 850 F04 09-SEP-07
for i in l: 10089 SLACKS 750 F03 20-OCT-08
if(i==‘E’ or i==‘e’):
e=e+1
elif(i==‘U’ or i==‘u’): TABLE: FABRIC
u=u+1 FCODE TYPE
print(“E :”,e) F04 POLYSTER
Page 6 Sample Paper 1 Computer Science Class 12
print (x[i]*2)
F02 COTTON
F03 SILK 30. Julie has created a dictionary containing names
and marks as key value pairs of 6 students. Write
F01 TERELENE
a program, with separate user defined functions
(i) To display GCODE and DESCRIPTION to perform the following operations
of each GARMENT in descending order (a) Push the keys (name of the student) of
of GCODE. the dictionary into a stack, where the
(ii) To display the details of all the corresponding value (marks) is greater than
GARMENTs, which have READYDATE 75.
in between 08-DEC-07 and 16-JUN-08 (b) Pop and display the content of the stack.
(inclusive of both the dates). For example If the sample content of the dictionary
(iii) To display the average PRICE of all the is as follows
GARMENTs. Which are made up of R={OM:76, JAI:45, BOB:89, ALI:65,
FABRIC with FCODE as F03. ANU:90, TOM:82}
(iv) To display FABRIC wise highest and The output from the program should be
lowest price of GARMENTs from TOM ANU BOB OM
GARMENT table.
Sol :
(Display FCODE of each GARMENT
alongwith highest and lowest price.) R={“OM”:76, “JAI”:45, “BOB”:89,
(b) Write a command to remove all the records of “ALI”: 65, “ANU”:90, “TOM”:82}
a table Shipping. def PUSH(S,N):
S.append(N)
Sol :
def POP(S):
(a) (i) SELECT GCODE, DESCRIPTION FROM if S!-[]:
GARMENT ORDER BY GCODE DESC; return S.pop()
(ii) SELECT*FROM GARMENT else:
WHERE READYDATE BETWEEN ‘08- return None
DEC-07’ AND ‘16-JUN-08’; ST=[ ]
(iii) SELECT AVG(PRICE) FROM GARMENT for k in R:
WHERE FCODE — ‘F03’; if R[k]>=75:
(iv) SELECT FCODE, MAX(PRICE), PUSH(ST, k)
MIN(PRICE) FROM GARMENT GROUP while True:
BY FCODE; if ST!=[]:
(b) DELETE FROM Shipping; print(POP(ST),end= “ ”)
else:
29. Write the definition of a function Reverse (x) in
break
Python, to display the elements in reverse order
or
such that each displayed element is the twice of
Alam has a list containing 10 integers. You need
the original element (element *2) of the List x in
to help him create a program with separate user
the following manner:
defined functions to perform the given operations
Example :
based on this list.
If List x contains 7 integers is as follows:
(a) Traverse the content of the list and push the
x [0] x [1] x [2] x [3] x [4] x [5] x [6] even numbers into a stack.
(b) Pop and display the content of the stack.
4 8 7 5 6 2 10 For example, If the sample content of the list is
After executing the function, the array content as follows
should be displayed as follows: N = [12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be:
20 4 12 10 14 16 8
38 22 98 56 34 12
Sol : Sol :
def Reverse (x): N = [12,13,34,56,21,79,98,22,35,38]
for i in range (len (x)–1,–1,–1): def PUSH(S, N):
Page 7 Sample Paper 1 Computer Science Class 12
Section - D
31. Red Pandas Infosystems has its 4 blocks of
buildings. The number of computers and distances
between them is given below :
(b) Consider the table Student whose fields are from database Mobile.
Consider:
Scode Name Age Strcde Points Grade host : localhost
101 Amit 16 1 6 NULL UserName : root
102 Arjun 13 3 4 NULL Password : system
Database : Mobile
103 Zaheer 14 2 1 NULL
Sol :
104 Gegen 15 5 2 NULL
(a) strl=input(“Enter the string:”)
105 Kumar 13 6 8 NULL final= “ ”
Write the Python code to update grade to A for for i in range (len(str1)):
all these students who are getting more than 8 as if (i%2==0):
points. final = final + strl[i]
print(“Modified string is :”, final)
The table structure is as follows :
(b) import mysql.connector as mydb
Scode : integer
mycon=mydb.connect (host =
Name : varchar
“localhost”,
Age : integer
user = “root”, passwd = “system”,
Strcde : integer
database = “Mobile”)
Points : integer
cursor = mycon.cursor ()
Grade : varchar
sql = “SELECT M_Id. M_Name,
Note the following to establish the connection
M_Supplier FROM MobileStock”
between Python and MySQL:
try:
Host : localhost
cursor.execute (sql)
Username : Admin
display = cursor, fetchall()
Password : Admin@123
for i in display
The table exists in MySQL database as : Student
print (i)
Sol : except:
(a) Output mycon.rollback()
The new string is : S1U3E5Ts mycon.close()
(b) import mysql.connector as mydb 33. What is CSV file?
con = mydb.connect (host = Write a program using two functions :
“localhost”, (a) addCustomer( ): To write Customer code,
user = “Admin”, Customer name and Amt in file cust.csv.
passwd = “Admin@123”, The details of the customers are as follows :
database = “system”) [CustCode, CustName, Amount]
cursor = con.cursor ( ) [001, Nihir, 8000]
sql = “UPDATE Student SET Grade = [104, Akshay, 5000]
‘A’ WHERE Points > 8” (b) readCustomer( ): To read the details of the
try : customers and display them.
cursor. execute (sql)
con.commit ( ) Sol :
except : CSV (Comma Separated Values) is a file format
con.rollback ( ) for data storage which looks like a text file.
con.close ( ) Program:
or import csv
(a) Write a Python program to remove the def addCustomer():
characters of odd index values in a string. f1 = open(‘cust.csv’, ‘w’, newline
(b) Consider the table MobileStock with following = “\n”)
fields w1= csv.writer(f1, delimiter =
M_Id. M_Name, M_Oty, M_Supplier “;”)
Write the Python code to fetch all records w1.writerow([‘CustCode’,
with fields M_Id, M_Name and M_Supplier ‘CustName’, ‘Amount’])
Page 9 Sample Paper 1 Computer Science Class 12
table.
(iii) (a) DELETE FROM MOVIEDETAILS WHERE
LANGUAGE=“ENGLISH”;
(b) INSERT INTO MOVIEDETAILS VALUES
(“M050”,“Palki”,“Hindi”, 5,
“Amazon Prime”);
or
(a) ALTER TABLE MOVIEDETAILS ADD
DAYS INTEGER;
(b) ALTER TABLE MOVIEDETAILS DROP
RATING;
Sol :
Section A (b) Foreign key
1. Given L= [2,3,4,5,6]. The output of print(L[2]) is 6. Which method returns the next row from the
(a) 6 (b) Error result set as tuple?
(c) 5 (d) 3 (a) fetchone () (b) fetchmany ()
(c) fetchall () (d) rowcount
Sol :
Sol :
(c) 5
(a) fetchone ()
2. The method used to get the position of file pointer
is 7. Which of the following command displays the
(a) tell() (b) get() attributes of a table along with their types and
(c) seek() (d) pos() sizes?
(a) Alter
Sol :
(b) Show structure
(a) tell() (c) Show create table
(d) View structure
3. This function is used to calculate total occurrence
of given elements of list. Sol :
(a) len() (b) sum() (c) Show create table
(c) count() (d) extend()
8. The............command adds records to a table.
Sol :
(a) ADD (b) APPEND
(c) count() (c) ADDRECORD (d) INSERT
4. You can repeat the elements of the tuple using Sol :
which operator? (d) INSERT
(a) * (b) +
(c) ** (d) % 9. In a............topology, the nodes are connected by
separate cables.
Sol :
(a) Star (b) Bus
(a) * (c) Tree (d) Mesh
10. Given a list Lst= [45,100,20,30,50]. What will be (c) uniquely identify a record
the output of Lst[: :]?
(a) [45,100,20,30,50] (b) [ ] Directions : (Q.Nos.-17 and 18) are Assertion and
(c) Error (d) [45] Reason based Questions.
Sol :
(b) r+ Section - B
15. The..........clause can be used as an alternative to
19. Find the error(s).
multiple OR.
L1 = [7, 2, 3, 4] Statement 1
(a) IN (b) BETWEEN
L2 = L1 + 2 Statement 2
(c) NOT (d) range
L3 = L1 * 2 Statement 3
Sol : L = L1.pop(7) Statement 4
(a) IN Sol :
16. The purpose of the primary key in a database is Error 1 L2 = L1 + 2 because + operator cannot
to add list with other type as number or string.
(a) unlock the database Error 2 L = L1.pop(7) parentheses puts index
(b) provide a map of the data value instead of element. In the given list,
(c) uniquely identify a record maximum index value is 3 and 7 is out of index
(d) establish constraints on database operations range.
Section - C 4
(ii) Make
5
26. (a) Consider the tables CARS and SUPPLIER (iii) CarName
given below. What will be the output of the SX4
statement given? C-Class
(iv) SUM(Charges)
TABLE: CARS
26
Ccode Car- Make Color Capa- Cha- Scode
Name city rges 27. Write a function Del() to delete the 4th word
501 A-star Suzuki RED 3 14 1 from a text file school.txt.
503 Indigo Tata SILVER 3 12 2 Sol :
502 Innova Toyota WHITE 7 15 2 def Del():
509 SX4 Suzuki SILVER 4 14 2 with open(‘school.txt’, ‘r’) as f:
510 C-Class Merc- RED 4 35 4 l = f.readlines()
edes f.close()
print(l)
Table : SUPPLIER del l[3]
print(l)
Scode Sname f = open (‘school.txt’, ‘w’)
1 Great Suppliers f.writelines(l)
2 Himalayan Vehicles f.close()
or
3 Road Motors Write a function countmy( ) in Python to read
4 Speed the text file Data.txt and count the number of
times my occurs in the file.
SELECT CarName, Sname, Charges FROM
For example If the file contents are:
CARS C, SUPPLIER S WHERE C.Scode= S.
My first book was. Me and My Family.
Scode AND Charges > 15;
It gave me chance to be known to the world.
(b) Write the output for SQL queries (i) to (iv),
The output of the function should be
which are based on the table CARDEN.
No. of times my occur : 2
TABLE: CARDEN
Sol :
Ccode CarName Make Color Capa- Charges
city def countmy():
501 A-star Suzuki RED 3 14
f=open(“Data.txt”, “r”)
count=0
503 Indigo Tata SILVER 3 12
x=f.read()
502 Innova Toyota WHITE 7 15 word=x.split()
509 SX4 Suzuki SILVER 4 14 for i in word:
510 C-Class Mercedes RED 4 35 if(i== “my”):
count=count+1
(i) SELECT COUNT(DISTINCT Make) FROM
print(“No. of times my occur :”,
CARDEN;
count)
(ii) SELECT COUNT(*) Make FROM CARDEN;
countmy()
(iii) SELECT CarName FROM CARDEN WHERE
Capacity = 4;
(iv) SELECT SUM (Charges) FROM CARDEN 28. (a) Write the output of the queries (i) to (iv)
WHERE Color = “SILVER”; based on the table FURNITURE given below.
Sol : Table : FURNITURE
(b) import mysql.connector 33. Does python create a file itself if the file doesnt
mycon = mysql.connector.connect exist in the memory? Illustrate your answer with
(host = “localhost”, user = an example:
“system”, passwd = “hello”, Write a program using following functions :
database =“Inventory”) (a) inputStud() :To input details of as many
cur = mycon.cursor() students and add them to a csv file college.
db = cur:execute (“CREATE TABLE csv without removing the previous records.
Production (PID varchar SrNo Studname City Percentage
(5) Primary key,
PName char (30), (b) readCollege() : To open the file college.csv
Price float, and display records whose city is Kolkata
Rank varchar(2)))”
Sol :
mycon.close( )
or Python will create a file automatically when the
(a) Find the output of the following program: open function is used with write mode.
def calcresult (): Example:
i=9 f=open(“data.txt”, “w”)
while i>1 : f.write(“Hello\nHow are you?”)
if(i%2 = = 0): f.close()
x = i%2 Program:
i = i – 1 import csv
else: def inputStud() :
i = i – 2 with open(“.college.csv”,”a”) as f:
x = i dt = writer(f)
print(x**2) while True:
(b) Which data will get added in table Company sno= int(input(“Enter Serial
by following code? No:”))
import mysql.connector stud_name = input(“Enter student
con = mysql.connector.connect ( name:”)
host = “localhost”, city = input(“Enter city:”)
user = “system”, perc = int(input(“Enter
passwd = “hello”, percentage:”))
database = “connect”). dt.Writerow([sno, stud_name,
cur = con.cursor ( ) city, perc])
sql = “insert into Company (Name, print(“Record has been added.”)
Dept, Salary) values (%s, print(“Want to add more record?
%s, %s)” Type YES!!!”)
val = (“ABC”, “DBA”, 35000) ch = input()
cur.execute (sql.val) ch = ch.upper()
con.commit ( ) if ch==“YES”:
Consider : print(“*********************”)
host : localhost else:
UserName : system break
Password : hello def readCollege():
Database ; connect with open(“college.csv”, ‘r’,)
as file:
Sol :
reader = csv.reader(file)
(a) Output for row in reader:
49 if row[2]== “Kolkata”
25 print(row)
9 file.close()
1 inputStud()
(b) ABC, DBA, 35000 readCollege()
Page 8 Sample Paper 1 Computer Science Class 12
or Section - E
Write a statement to create a data.txt file with
the following text.
Python file handling is very interesting and useful. 34. Consider the table APPLICANTS
Write a python code using two functions as follows
TABLE: APPLICANTS
(a) removerow( ) : To remove a record from the
college file College.csv having following No NAME FEE GEN- C_ JOINYEAR
DER ID
structure.
1012 Amandeep 30000 M A01 2012
SrNo Studname City Percentage
1102 Avisha 25000 F A02 2009
(b) getCollege( ) : To read the records of the
1103 Ekant 30000 M A02 2011
college file College.csv and display names of
students whose names start with a lowercase 1049 Arun 30000 M A03 2009
vowel. 1025 Amber 40000 M A02 2011
1106 Ela 40000 F A05 2010
Sol :
1017 Nikita 35000 F A03 2012
f=open(“data.txt”, “w”)
1108 Arluna 30000 F A03 2012
f.write(“Python file handling is very
interesting and useful.”) 2109 Shakti 35000 M A04 2011
f.close() 1101 Kirat 25000 M A01 2012
Program : (i) Which field qualifies to be the Primary key.
import csv (ii) If all the records of Male applicants are
def removerow( ): deleted, what will be the cardinality of the
record = list() table.
sname= input(“Please enter a (iii) Write statements to
customer name to delete:”) (a) Increase FEE of M (Male) applicatnts
with open(‘College.csv’, ‘r’) by 2000.
as f: (b) Display details of F (Female) applicants
data = csv.reader(f) in descending order of FEE.
for row in data: or
record.append(row) (Option for part (iii) only)
for field in row: Write statements to
if field == sname: (a) Change width of column FEE to 20.
record.remove(row) (b) Remove the column C_ID.
with open(‘College.csv.’, ‘w’)
as f: Sol :
writer = csv.writer(f) (i) The No column can be the Primary key.
writer.writerows(record) (ii) 4
def getCollege(): (iii) (a) UPDATE APPLICANTS SET
with open(“College.csv”, ‘r’) FEE=FEE+2000 WHERE GENDER =
as file: “M”;
reader = csv.reader(file) (b) SELECT * FROM APPLICANTS WHERE
for row in reader: GENDER = “F” ORDER BY FEE DESC;
if row[1][0] in ‘aeiou’: or
print(row) (a) ALTER TABLE APPLICANTS MODIFY
file.close() FEE INTEGER (20);
removerow() (b) ALTER TABLE APPLICANTS DROP C_
getCollege() ID;
s =.......... Line 2
print(s)
myfile.close( )
(i) In which mode is the file opend?
(ii) If the entire file is to be read, write a statement
in place of Line 2.
(iii) What is the original code performing?
Sol :
(i) Read mode
(ii) s=myfile.read( )
(iii) The code opens a text file detail.txt, reads
10 characters from it and displays them.
Finally, the file is closed.
Page 1 Sample Paper 1 Computer Science Class 12
Sol :
Section A (a) Relative
(c) Foreign key 15. Which of the following function returns the total
number of values?
10. Assume that the position of the file pointer is at (a) MAX (b) MIN
the beginning of 3rd line in a text file. Which of (c) COUNT (d) SUM
the following option can be used to read all the
remaining lines? Sol :
(a) myfile.read(n-3) (b) myfile.read(n) (c) COUNT
(c) myfile.readline( ) (d) myfile.readlines( )
16. Which of the following is the correct output for
Sol : the following execution ?
(d) myfile.readlines( ) print(print(“Biscope”))
(a) Biscope (b) None
11. ______is a protocol used for uploading and (c) Biscope (d) Error
downloading of files in a network. None
(a) SMTP (b) FTP
(c) PPP (d) VoIP Sol :
(i) SELECT * FROM Train WHERE Start= (ii) SELECT CNAME FROM CUSTOMER
“NDLS”; WHERE CNAME LIKE ‘L%’;
(ii) SELECT AVG(Perc) FROM Student; (iii) SELECT DISTINCT AREA FROM
CUSTOMER;
(iv) SE.LECT’COUNT(*) FROM CUSTOMER
Section - C WHERE GENDER=“MALE”;
Sol :
26. (a) Consider the tables CITY and LOCATION
(a) SELECT C. Cityname , L.Lname FROM
given below.
City C,
Table : CITY LOCATION L WHERE C.Citycode= L.
Citycode AND AVGTEMP>35;
Field Name Data Type Remarks
(b) (i)
CITYCODE CHAR(5) Primary Key
COUNT (*) GENDER
CITYNAME CHAR(30)
4 FEMALE
SIZE INTEGER
AVGTEMP INTEGER
6 MALE
(ii) No rows selected
POPULATIONRATE INTEGER
(iii)
POPULATION INTEGER
DISTINCT AREA
C1 East EAST
C2 West WEST
(iv)
C3 South
COUNT (*)
C4 North
6
Write a command to display the Cityname and
corresponding Location name (Lname), where the 27. Write a Python program that read the data from
average temperature is greater than 35 from the file original.dat and delete the line(s) having
tables. word (passed as an argument). Then write these
(b) Write outputs for the SQL commands (i) to data after removing lines into file duplicate.dat.
(iv) based on the table CUSTOMER given
Sol :
below:
TABLE: CUSTOMER import os
def Delete (word):
CID CNAME GENDER SID AREA
file1=open(‘original.dat’, ‘rb’)
1001 R SHARMA FEMALE 101 NORTH nfile=open(‘duplicate.dat’, ‘wb’)
1002 M R TIWARY MALE 102 SOUTH while True :
1003 M K KHAN MALE 103 EAST line=file1.readline()
1004 A K SINGH MALE 102 EAST
if not line :
break
1005 S SEN FEMALE 101 WEST
else :
1006 R DUBEY MALE 104 NORTH if word in line :
1007 M AGARWAL FEMALE 104 NORTH pass
1008 S DAS FEMALE 103 SOUTH else:
print(line)
1009 R K PATIL MALE 102 NORTH
nfile.write(line)
1010 N KRISHNA MALE 102 SOUTH
file1.close()
MURTY
nfile.close()
(i) SELECT COUNT(*), GENDER FROM
or
CUSTOMER GROUP BY GENDER;
Page 5 Sample Paper 1 Computer Science Class 12
type of network will be formed? Note the following to establish the connection
between Python and MySQL:
Sol : Host : localhost
(i) TTC should install its server in finance Username : system
block as it is having maximum number of Password : test
computers. Database : Inventory
(ii) Sol :
(a) 50#5
(b) Yes, she can add new column after creation of
table.
import mysql.connector
mycon = mysql.connector.connect(
host = “local host”,
user = “system”,
passwd = “test”,
The above layout is based on minimum cable database = “Inventory”)
length required, which is 120 m in the above case. cursor = mycon.cursor( )
(iii) Star topology, as it has independent cursor.execute(“ALTER TABLE Item
connections that help easy network setup and ADD ManufacturingDate Date NOT
fault detection. NULL”) mycon.close ( )
(iv) (a) Switch/Hub These are devices that can or
connect multiple nodes in a network, (a) Find the output of the following code :
together. Name= “PythoN3@1”
(v) Since, the distance is less than 1 km. R=“ ”
LAN (Local Area Network) will be formed. for x in range(len(Name)):
if Name[x].isupper():
32. (a) What will be the output of the following R=R+Name[x].lower()
code? elif Name[x].islower():
value = 50 R=R+Name[x].upper()
def display(N): elif Name[x].isdigit():
global value R=R+Name[x–1]
value = 25 else:
if N%7==0 R=R+ “#”
value = value + N print(R)
else: (b) Consider the following table structure
value = value — N Table: Faculty
print(value. end= “#”) F_ID(P)
display(20) Fname
print(value) Lname
(b) Given below is a table Item in database Hire_date
Inventory. Salary
ItemID ItemName Quantity UnitPrice Write the Python code to create the above table.
Consider :
101 ABC 5 120
host : localhost
102 XYZ 7 70 UserName : root
103 PQR 8 65 Password : system
Database :School
104 XYZ 12 55
Riya created this table but forget to add column Sol :
ManufacturingDate. Can she add this column (a) pYTHOnN#@
after creation of table? If yes, write the code (b) import mysql.connector
where users name and password are system and mycon = mysql. connector.connect(
test respectively. host = “localhost”,
Page 8 Sample Paper 1 Computer Science Class 12
lines=myf....... . Blank 3
Section-E for ln in .... . . : Blank 4
if ln[0]= = “A”:
34. Consider the following table STORE and answer print(ln)
the questions: (i) Write the missing code for Blank 1.
TABLE: STORE (ii) Write the missing code for Blank 2.
ItemNo Item Scode Qty Rate LastBuy
(iii) Write the missing code for Blank 3 and Blank
4.
2005 Sharpener 23 60 8 31-JUN-09
Classic Sol :
2003 Balls 22 50 25 01-FEB-10 (i) para.txt
2002 Gel Pen 21 150 12 24-FEB-10 (ii) r
Premium (iii) readlines( ), lines.
2006 Gel Pen 21 250 20 11-MAR-09
Classic
2001 Eraser 22 220 6 19-JAN-09
Small
2004 Eraser Big 22 110 8 02-DEC-09
2009 Ball Pen 0.5 21 180 18 03-NOV-09
Sol : Sol :
(d) All of these (a) Both A and R are true and R is the correct
explanation of A.
12. in and not in are........Operators.
(a) Arithmetic (b) Membership 18. Assertion (A) A binary file uses the dump()
(c) Logical (d) Identity function to write data into it.
Reason (R) The load() function reads data from
Sol : a binary file.
(b) Membership (a) Both A and R are true and R is the correct
explanation of A.
13. Modulation and demodulation is performed by (b) Both A and R are true but R is not the
(a) microwave (b) satellite correct explanation of A.
(c) modem (d) gateway (c) A is True but R is false.
Sol : (d) A is false but R is true.
(c) modem Sol :
(b) Both A and R are true but R is not the correct
14. A set of possible data values is called
explanation of A.
(a) attribute (b) degree
(c) tuple (d) domain
Sol : Section B
(d) domain
19. What will be the output of following code ?
15. The..........attribute of the connection string L=[10,30,50,60]
specifies the password to connect to the database. L.append(70)
(a) code (b) password L.insert(2,80)
(c) passwd (d) All of these L.sort()
Sol : print(L)
(c) passwd Sol :
16. While opening a binary file the.........character has [10, 30, 50, 60, 70, 80]
to be added to the mode of opening. 20. Write 2 advantage and 2 disadvantage of bus
(a) b (b) x topology.
(c) u (d) b*
Sol :
Sol :
Advantages of Bus Topology
(a) b (i) All the nodes are connected directly, so very
Directions (Q.Nos. 17-18) are Assertion and short cable length is required.
Reason based questions. (ii) The architecture is very simple, reliable and
linear.
Page 3 Sample Paper 1 Computer Science Class 12
21. Find outputs of following code. 24. What will be the output of the following code,
(a) L=[118,16,[20,30,50],120] when executed?
L1=[12,16,17] d={‘Name’: ‘Ram’,‘Subjects’:[‘Eng’,
L.extend(L1) ‘Physics’, ‘CS’], ‘Marks’:[67,78,90]}
print(L[2][2]) print(d[‘Subjects’])
print(L) print(d[‘Subjects’][2])
(b) t1=(9,6,1,12) Sol :
t2=(10,11,12)
print(t1+t2) [Eng,Physics,CS]
print(t1*2) CS
print(t2–t1) or
What will be the output of the following code,
Sol : when executed?
(a) 50 tupnames=(“India”, “Australia”,
[118, 16, [20, 30, 50], 120, 12, 16, 17] (“UK”, “Nepal”), “Bangladesh”)
(b) (9, 6, 1, 12, 10, 11, 12) print(tupnames[5 : ])
(9, 6, 1, 12, 9, 6, 1, 12) print(tupnames[2][1])
Error Sol :
22. What do you understand by primary key? Give ()
a suitable example of primary key from a table Nepal
containing some meaningful data.
25. List the major components of a database system.
Sol :
Sol :
Page 4 Sample Paper 1 Computer Science Class 12
The major components of a database system are 2002 Gel Pen 21 150 12 24-FEB-10
(i) User (ii) Hardware Premium
(iii) Software (iv) Data 2006 Gel Pen 21 250 20 11-MAR-09
or Classic
What is join? What are the different kinds of 2001 Eraser 22 220 6 19-JAN-09
joins? Small
33. What are the advantages of CSV files? (ii) There is no distinction between text and
Write a python program using following functions numeric values
to : Program:
A file teacher.csv contains a city, teacher name import csv
and Salamount. def addTransaction ( ):
(a) Search() : Search and print all rows where f1 = open (“bank.csv”,‘w’,
city is delhi. newline = “\n”)
Sample teacher.csv : w1 = csv.writer(f1, delimiter
= “\t”)
City Teacher Name Salamount w1.writerow([‘TranID’,
Delhi, Anil Sharma, 10000 ‘TranDate’, ‘Amount’, ‘Type’])
while True:
Pune, Mr Dua, 20000
op = int(input(“Enter 1 to add
Delhi, Mr Das, 25000 and 0 to exit”))
(b) Searchfromfile() : From the file teacher.csv if(op == 1):
print all rows where teacher name is Anil. TranID = int(input(“Enter
transaction ID: ”))
Sol :
Trandate = input(“Enter date:
Advantages of CSV: ”)
(i) CSV is faster to handle Amount = int(input(“Enter
(ii) CSV is smaller in size and is easy to generate amount: ”))
Program : Type=input(“Enter transaction
import csv type : ”))
def Search(): w1.writerow([TranID, Trandate,
f = open(“teacher.csv”, ‘r’) Amount, Type])
r = csv.reader(f, delimiter = ‘,’) elif op == 0:
for row in r : break
if row[0].lower()==”delhi: f1.close()
print(row[1], row[2]) def getTran():
f.close() f = open(“bank.csv”, ‘r’)
def Searchfromfile(): r = csv.reader(f, delimiter = ‘,’)
f = open(“teacher.csv”, ‘r’) for row in r :
r = csv.reader(f, delimiter = ‘,’) if “Deposit” in row[3] :
for row in r : print(row)
if “Anil” in row[1] : f.close()
print(row[1], row[2]) addTransaction()
f.close() getTran()
Search()
Searchfromfile()
or Section E
What are the Disadvantages of CSV files?
Write a program using functions :
34. Consider the following table Student:
(a) addTransaction() : To append bank
transactions of following structure to bank. Table : Student
csv
AdmNo RollNo Name Class Marks
TranlD TranDate Amount Type
(b) getTran() : To display those transactions 2715 1 Ram 12 90
whose type is Deposit. 2816 2 Shyam 11 95
Sol : 2404 3 Ajay 10 92
Disadvantages of CSV files are 2917 4 Tarun 12 94
(i) There is no standard way to represent the
(i) Can we make Class as the Primary key of the
binary data
table?
Page 9 Sample Paper 1 Computer Science Class 12
(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
Page 1 Sample Paper 1 Computer Science Class 12
(b) Identity 15. To open a text file for adding records keeping the
existing records the mode should be
10. What will the following code display? (a) ab (b) xb
name = “Neha” (c) rb (d) w+
type (name)
(a) Invalid function <type> Sol :
(b) <class ‘str’> (d) w+
(c) <class ‘int’>
(d) <class ‘float’> 16. A device that connects two dissimilar networks is
(a) Modem
Sol : (b) Repeater
(b) <class str> (c) Bridge
(d) Gateway
11. Which of the following is not required while
Sol :
specifying the connection string in database
connection? (d) Gateway
(a) Host
Directions : (Q.Nos. 17-18) are Assertion and
(b) Table name Reason based questions.
(c) Username
(d) Password 17. Assertion (A) Binary files are processed faster
than text files.
Sol : Reasoning (R) They are written in Binary format
(b) Table name and are more close to the computer.
(a) Both A and R are true and R is the correct
12. The ALTER TABLE command belongs to............. explanation for A.
category (b) Both A and R are true and R is not the
(a) DML (b) TCL correct explanation for A.
(c) DDL (d) DCL
(c) A is true but R is false.
Sol :
(d) A is false but R is true.
(c) DDL
Sol :
13. Which of the following are possible relational
operations? (a) Both A and R are true and R is the correct
(a) Join explanation for A.
fobj=open(“data.dat”,“rb”)
6 Ketaki 16 ENT 24/02/98 300 F
ano=input(“Enter student no. to
7 Ankita 29 Cardiology 20/02/98 800 F
search :”)
st1st=[] 8 Zareen 45 Gynaecology 22/02/98 300 F
found=0 9 Kush 19 Cardiology 13/01/98 800 M
while True: 10 Shailya 31 Nuclear 19/02/98 400 M
try: Medicine
st1st=pickle.load(fobj) (i) To show all information about the
if ano==st1st[0]: patients of Cardiology Department.
print(“Found”)
print(“Name :”, st1st[1]) (ii) To list the name of female patients, who
print(“Marks :”, st1st[2]) are in Orthopaedic Department.
found=1 (iii) To list names of all patients with their
break date of admission in ascending order.
except EOFError:
(iv) To display Patients Name, Charges, Age
print(“Not found”)
for male patients only.
break
if found==0: (b) Write the command to view all the tables in
print(“Search Unsuccessful ”) database.
fobj.close() Sol :
or
(a) (i) SELECT FROM HOSPITAL WHERE
import os
Department = Cardiology;
def countand():
if os.path.isfile(“status.txt”): (ii) SELECT Name FROM HOSPITAL
fob=open(“status.txt”, ‘r’) WHERE Department = Orthopaedic
c=0 AND Sex = F;
while True: (iii) SELECT Name FROM HOSPITAL
Str=fob.readline() ORDER BY Dateofadm;
if not Str:
break (iv) SELECT Name, Charges, Age FROM
Str=Str.rstrip().lower(). HOSPITAL WHERE Sex = M;
split() (b) Show tables
for i in range(len(Str)):
if (Str[i]==‘and’ or Str[i]== 29. Write user defined functions factors(num) and
‘AND’): factorial(num) to find the factors and factorial of
c=c+1 a number accepted from the user and passed to
print(“Count of_and_in file is/ the functions from main function.
are : ”,c) Sol :
else:
def factorial(num):
print(“File does not exist”)
f=1
countand()
for i in range(1,(num+1)):
28. (a) Write the SQL commands for (i) to (iv) on f*=i
the basis of the table HOSPITAL print(“Factorial :”,f)
def factors(num):
TABLE: HOSPITAL print(“Factors of ”,num)
No Name Age Department Date- Cha- Sex for i in range(1,(num+1)):
ofadm rges if num%i==0:
1 Sandeep 65 Surgery 23/02/98 300 M print(i)
2 Ravine 24 Orthopaedic 20/01/98 200 F def main():
3 Karan 45 Orthopaedic 19/02/98 200 M
n=int(input(“Enter a number :”))
factorial(n)
4 Tarun 12 Surgery 01/01/98 300 M
factors(n)
5 Zubin 36 ENT 12/01/98 250 M main()
Page 6 Sample Paper 1 Computer Science Class 12
50 Push 75, 50 (i) Suggest the most suitable place (i.e. block/
Centre) to install the server of this university
80 Push 75, 50, 80 with a suitable reason.
(ii) Suggest an ideal layout for connecting these
+ Pop twice 50+ 80=130 75, 130
block/Centre for a wired connectivity.
+ Pop twice 130 + 205 (iii) Which device you will suggest to be placed/
75=205 installed in each of these blocks/Centre to
efficiently connect all the computers with in
Output 205 these blocks/Centre ?
(iv) The university is planning to connect its
admission office in the closest big city, which
is more than 250 km from university, which
type of network out of LAN, MAN or WAN
will be formed? Justify your answer.
(v) Expand the following
LAN
Page 7 Sample Paper 1 Computer Science Class 12
float(6,1);
or
(a) SELECT CabType FROM Cab WHERE
Rate>25;
(b) SELECT CabID, Nop, FROM Cab
WHERE CabType = “Sedan”;
END
Page 1 Sample Paper 1 Computer Science Class 12
b = 1
Section A for a in range(1, 10, 2):
b += a + 2
1. Which of the following functions write data to a print(b)
binary file? (a) 31 (b) 33
(a) pickle() (b) writer() (c) 36 (d) 39
(c) load() (d) dump()
Sol :
Sol :
(c) 36
(d) dump()
6. Which of the following Python function displays
2. _____can be create using cursor( ) method of the memory id of a variable?
connection object. (a) type( ) (b) str( )
(a) Cursor object (b) Cursor variable (c) getid( ) (d) id( )
(c) Connect (d) None of these
Sol :
Sol :
(d) id( )
(a) Cursor object
7. Which of the following is an advantage of SQL?
3. _____command displays the contents of a (a) High speed
table. (b) Client/Server language
(a) DISPLAY (c) Easy to learn
(b) VIEW (d) All of these
(c) SELECT
Sol :
(d) SHOW
(d) All of these
Sol :
(c) SELECT 8. Which of the following operator performs an
integer division?
4. State True or False (a) * (b) //
Integer is a mutable data type in Python. (c) / (d) **
Sol : Sol :
False (b) //
5. Identify the output of the following Python 9. Predict the output of the following program:
statement: a = 5
Page 2 Sample Paper 1 Computer Science Class 12
b = a = 15 (a) read()
c = (a < 15)
print (“a = ”, a) 15. The cross join is also called
print (“b = ”, b) (a) Merging
print (“c = ”, c) (b) Cartesian product
(a) a=15 (b) a=15 (c) Natural join
b=15 b=10 (d) Equi join
c=False c=True Sol :
(c) a=15 (d) None of these
b=None (b) Cartesian product
c=False
16. ______is the base protocol for all application
Sol : protocols.
(a) a=15 (a) FTP
b=15 (b) TCP/IP
c=False (c) IRCP
(d) Telnet
10. Given s=AISSE@2023. What will be the output
of print(s[-1: :-1])? Sol :
(a) 3202@ESSIA (b) 3
(b) TCP/IP
(c) AISSE (d) ESSIA
Sol : Direction : (Q.Nos. 17-18) are Assertion and
Reason based questions.
(a) 3202@ESSIA
17. Assertion (A)Pickling is a way to convey a Python
11. A primary key of a relation must be_____. object into character stream.
(a) UNIQUE only Reason (R) To perform pickling, the pickle module
(b) NOT NULL only needs to be imported.
(c) Both UNIQUE and NOT NULL (a) Both A and R are true and R is the correct
(d) Neither UNIQUE nor NOT NULL explanation for A.
Sol : (b) Both A and R are true but R is not the
(c) Both UNIQUE and NOT NULL correct explanation for A.
(c) A is true but R is false.
12. The........clause can group records on the basis of (d) A is false but R is true. A.
common values in a field.
(a) AGGREGATE (b) GROUP Sol :
(c) GROUP BY (d) JOIN (b) Both A and R are true but R is not the correct
Sol : explanation for A.
(c) GROUP BY 18. Assertion (A) A recursive function does not
require a loop.
13. The python function that adds a list at the end
Reason (R) A recursive function calls itself again
of another list is
and again until a certain condition is true.
(a) join() (b) add()
(a) Both A and R are true and R is the correct
(c) append() (d) extend()
explanation for A.
Sol : (b) Both A and R are true but R is not the
(d) extend() correct explanation for A.
(c) A is true but R is false.
14. Which of the following functions will read entire
(d) A is false but R is true.
contents of a text file?
(a) read() (b) readfull() Sol :
(c) readline() (d) readfile()
(a) Both A and R are true and R is the correct
Sol : explanation for A.
Page 3 Sample Paper 1 Computer Science Class 12
Sol :
Section B
Database The database is a shared collection
19. Observe the code given below and find the output of logically related data, designed to meet the
: information needs of an organisation. A database
s= “oceanview” is a computer based record keeping system whose
count=0 over all purpose is . to record and maintains
for a in s: information.
if a in “stuv”: DBMS A Database Management System (DBMS)
count+=1 is a collection of programs that enables users to
print(count) store, modify and extract information from a
database as per the requirements. It acts as an
Sol : interface between the application program and
1 the operating system to access or manipulate the
The for loop checks for existence of the characters database.
of the string in stuv , and returns the count. 23. (a) Write the full forms of :
(i) RJ45 (ii) XML
20. What is the difference between video conferencing (b) Write one advantages of Bus topology
and chat? compared to Star and one advantage of star
or topology compared to Bus.
What is WWW?
Sol :
Sol :
(a) (i) Registered Jack 45
Chat generally involves one-to-one communication. (ii) eXtensible Markup Language
On the other hand, video conferencing means more
(b) Advantage of Bus over star : Economically
than two persons are involved in a discussion.
better as a single backbone cable connects all
or
the computers.
WWW (World Wide Web) is a system of Internet
servers that supports hypertext and multimedia Advantage of Star over bus : Fault detection
to access several Internet protocols on a single and isolation is easy.
interface. This web standard allows programs on
24. What output will the following code produce?
many different computer platforms to properly
y=str(123)
format and display the information server.
x= “hello”*3
21. (a) Given the following code :
print(x,y)
d={‘Bed’:145000, ‘Almirah’:9000,
x=“hello” + “world”
‘Chair’:1000}
y=len(x)
for v in d.keys():
print(y,x)
if d[v]>100000:
or
d[v]– =10000
Write function names for the following with
print(d)
respect to strings.
What will be the output of the print statement?
(i) To make the first letter of a string in capital
(b) Write the value stored in the variable Num by
(ii) To find the index of the 1st occurrence of a
each of the following statements.
string in another
(i) Num = 2 * 3 4
(ii) Num = 2+31*3 Sol :
(iii) Num = (2+3)*2 hellohellohello 123
Sol : 10 helloworld
or
(a) {Bed: 135000, Almirah: 9000, Chair:
(i) capitalize()- Returns a copy of the string with
1000}
the 1st character capitalized.
(b) (i) Num = 2
(ii) find() - Returns the lowest index in a string
(ii) Num = 2
where another string is found.
(iii) Num = 10
Sol : 5 35000 15
DDL (Data Definition Language) provides With respect to the tables given above write a
statements for creation and deletion of the command to display the Lastname, Firstname
database tables, views, etc. The DDL provides a and corresponding order number arranged by
set of definitions to specify the storage structure Lastname.
in a database system. (b) With respect to the table PAYMENTS
Some DDL statements are as follows given below, write, output of the following
(i) CREATE used to create new table in the questions.
database.
(ii) DROP used to delete tables from the TABLE : PAYMENTS
database. Empld Emp_Name Salary Department
(iii) ALTER used to change the structure of the
1 Ridhi 20000 D1
database table. This statement can add up
additional column, drop existing, and even 2 Rohit 25000 D2
change the data type of columns involved in a 3 Rakesh 20000 D2
database table.
(iv) RENAME used to rename a table. 4 Roshan 44000 D1
or 5 Rohini 15000 D3
DML (Data Manipulation Language) provides 6 Radha 14000 D1
statements for manipulating the database objects.
It is used to query the databases for information (i) To display the average of employees salary
retrieval. Some DML statements are as follows from PAYMENTS table.
(i) INSERT used to insert data into a table. (ii) To count the total number of employees from
(ii) SELECT used to retrieve data from a PAYMENTS table Department wise
database. (iii) To count distinct values of column Department
(iii) UPDATE used to update existing data within from PAYMENTS table.
a table. (iv) To display department wise number of
(iv) DELETE used to delete all records from a employees , but for only those departments
table. where number of employees are more than 2.
Sol :
Section C (a) SELECT Last_Name, First_Name,
Order_No
26. (a) Consider the following tables PERSON and
ORDERS FROM PERSON, ORDERS
WHERE PERSON.P_Id = ORDERS.P_Id
Table : PERSON ORDER BY PERSON.Last_Name;
P_Id Last_Name First_Name City (b) (i) SELECT AVG(Salary) FROM
1 Sharma Abhay Mumbai PAYMENTS;
2 Gupta Mohan Delhi (ii) SELECT Department, COUNT(*)
FROM PAYMENTS GROUP BY
3 Verma Akhil Mumbai Department;
(iii) SELECT COUNT(DISTINCT
Table : ORDERS Department) FROM PAYMENTS;
O_Id Order_No P_Id (iv) SELECT Department, COUNT(*)
1 10050 3
FROM PAYMENTS GROUP BY
Department HAVING COUNT(*) >2;
2 25000 3
Page 5 Sample Paper 1 Computer Science Class 12
(b) Write the command to display the sum of display elements in a stack.
prices of items of type cot. Algorithm Steps to Display all the Elements of
the Stack
Sol :
1. Start
(a) (i) SELECT * FROM INTERIORS WHERE 2. if (Top == – 1)go to step 3
TYPE = ‘Sofa’; else go to step 4
(ii) SELECT ITEMNAME FROM INTERIORS 3. Print “Stack is empty” and go to
WHERE PRICE > 10000; step 7
(iii) SELECT ITEMNAME, TYPE FROM 4. Print the Top element of the stack
INTERIORS WHERE DATEOFSTOCK < 5. Decrement Top by 1
‘22/01/02’ ORDER BY ITEMNAME 6. if (Top == – 1) go to step 7
DESC; else go to step 4
(iv) INSERT INTO INTERIORS VALUES 7. Stop
(14, ‘TrueIndian’, ‘Office or
Table’, ‘25/03/03’, 15000,
Scanned Operation Stack
20);
Elements status
(b) SELECT SUM(PRICE) FROM INTERIORS
WHERE Type LIKE “%cot”; 7 Push 7
11 Push 7, 11
29. Write a user defined function to accept a string
and check whether it is palindrome or not. * Pop twice 7*11 = 77 77
(A palindrome is a string that is same as its 80 Push 77, 80
reverse)
+ Pop twice 77+80=157 157
Sol :
50 Push 157, 50
def checkPalin( ):
+ Pop twice 157 + 50 = 207 207
string = input (“Enter the string:”)
str1 = “” Output 207
for i in string:
str1 = i + str1
print (“string in reverse order:”, Section D
str1)
if (string == str1): 31. Tech Up Corporation (TUC) is a professional
print (“This is a palindrome consultancy company. The company is planning
string”) to set up their new offices in. India with its hub
else : at Hyderabad. As a network adviser, you have
print (“This is not a palindrome to understand their requirement and suggest to
string”) them the best available solutions. Their queries
are mentioned as (i) to (v) below.
30. Explain the traversal operation in a stack. Physical locations of the blocks of TUC
Write the algorithm for Traversal of a stack to
display its contents.
You need not to write the actual code.
or
Find the final contents of a stack that encounters
the following tokens.
Assume that an operand is pushed to stack and
a binary operator pops two operands from stack
and pushes the result to the stack.
7,11,*,80,+,50,+ Block to block distances (in metre)
Sol : Block (From) Block (To) Distance
Moving through the elements of the stack is known Human Resource Conference 60
as traversal. Traversing is the basic operation to
Page 7 Sample Paper 1 Computer Science Class 12
Human Resource Finance 120 (b) Write a code in Python to update the class of
a student to 12 whose roll number is 22. The
Conference Finance 80 table structure is as follows :
Expected number of computers to be installed RollNo Name Class Perc
in each block Note :
Database : PythonDB
Block Computers Table : Student
Human Resource 125 Host : localhost
UserId : root
Finance 25
Password : arihant
Conference 60 or
(i) What will the most appropriate block, where (a) Write the output of the following function
TUC should plan to install their server? def showOutput( ):
(ii) Draw a block to block cable layout to connect num=4 + float(7)/int(2.0)
all the buildings in the most appropriate print(“num =”, num)
manner for efficient communication. (b) Write a code in Python to delete the record
(iii) Write names of different types of Modems. of a student whose rollno is 33. The table
(iv) Which of the following devices will be structure is as follows
suggested by you to connect each computer RollNo Name Class Perc
in each of the buildings? Note :
(a) Gateway (b) Switch (c) Modem Database : PythonDB
(v) Company is planning to connect its Block in Table : Student
Hyderabad which is more than 20 km. Which Host : localhost
type of network will be formed? UserId : root
Password : arihant
Sol :
Sol :
(i) TUC should install its server in Human
Resource Block as it has maximum number (a) Corrected code
of computers. s=“WelcometoCS”
(ii) for a in s :
if a in “aeiou” :
print(a)
else :
print(“False”)
(b) import mysql.connector
con = mysql.connector.connect
(host = “localhost”, user = “root”,
passwd = “arihant”,
The above layout is based on the minimum
database = “PythonDB”)
length of cable required, i.e. 140 m.
cursor = con.cursor()
(iii) Internal Modem : Fixed inside the computer.
try :
External Modem : Attached externally to a
cursor.execute (“update Student
computer
set Class = 12 where RollNo 22”)
(iv) (b) Switch
con.commit()
(v) MAN
except :
32. (a) Underline the errors in the following code and con.rollback()
write the correct code: con.close()
s= “WelcometoCS” or
For a IN s : (a) num = 7.5
If a IN “aeiou” : (b) import mysql.connector
print(a) con = mysql.connector.connect
else (host = “localhost”, user = “root”,
print(“False”) passwd = “arihant”,
Page 8 Sample Paper 1 Computer Science Class 12
Sol : Sol :
20. Identify the types of networks formed in the (ii) High speed SQL queries can be used to
following cases : retrieve large amount of records from a
(a) Two friends sharing files between a distance database quickly and efficiently.
of 1000 km. (iii) Easy to learn and understand SQL generally
(b) A device transmitting voice to stations within consists of english language statements and it
a distance of 30 km. is very easy to learn and understand.
or (iv) SQL is used for relational database SQL is
Write names of protocols used in following cases : widely used for relational database.
(a) A network user downloading a photograph
from a server 23. (a) Identify whether the following address is a
(b) Two friends chatting over the web. valid IP address or not 256.200.192.1
(b) What is the difference between domain name
Sol : and IP address?
(a) WAN - Wide Area Network Sol :
(b) MAN - Metropolitan Area Network
or (a) It is not an IP address as the numbers in the
(a) FTP - File Transfer Protocol IP addresses can be within 0-255.
(b) IRCP - Internet Relay Chat Protocol (b) IP address is an identifier for a computer or
device on a TCP/IP network.
21. (a) Given the following code : e.g. 1.160.10.240 could be an IP address.
str1 = input (“Enter the string:”) A domain name is a name that identifies one
final = “” or more IP addresses.
for i in range(len(str1)): e.g. The domain name microsoft.com
if (i%2 == 0): represents about a dozen IP addresses.
final = final + str1[i]
print(“Modified string is : ”, 24. Distinguish between tuple and list.
final) or
What is the above code doing? How can you add following data in empty
(b) Consider the following list and answer the dictionary?
below questions. Keys Values
l = [6, 9, 8, ‘Hi’, ‘Hello’, 45,
23, ‘New’] A One
(i) l[4:] B Two
(ii) l[-4]
C Three
(iii) l[2:5]
(iv) ‘World’ in l D Four
Sol : Sol :
(a) The code removes the characters-at the odd Differences between tuple and list are as follows
indices of a string. The loop iterates through Tuple List
the length of the string and Checks the
Elements of a tuple are Elements of a list are
even positions. Extracts characters at these
immutable. mutable.
positions and creates a new string.
(b) (i) [Hello, 45, 23, New] Tuple is declared in List is declared in
(ii) Hello parenthesis (). square brackets [ ].
(iii) [8, Hi, Hello] Tuples cannot be Lists can be changed
(iv) False changed after creation. after creation.
22. Write few advantages of SQL. Iterating over the Iterating over the
elements of a tuple is elements of a list is
Sol :
fast. slow.
(i) SQL is portable It is not platform dependent, or
it can be used in all types of devices; PCs, dic = { }
laptops and even mobile phones also. dic[‘A’] = ‘One’
Page 4 Sample Paper 1 Computer Science Class 12
dic[‘B’] = ‘Two’
dic[‘C’] = ‘Three’
Section C
dic[‘D’] = ‘Four’
26. (a) Consider the tables EMP and SALGRADE
25. What is equi join ? Explain with an example. storing details of employees and their salaries.
or
Table: EMP
Identify which of the functions given below are
aggregate functions. empno ename sal date
COUNT() , LEFT() , RIGHT() , MAX() , AVG() 110 Priya 7000 11-11-2010
, TRIM()
111 Seema 14000 15-02-2014
Sol :
151 Sachin 30000 18-04-2015
Equi join is a simple SQL join condition that uses
142 Deepa 25000 20-05-2015
equal sign as a comparison operator.
Syntax
SELECT col1, col2, col3 Table : SALGRADE
FROM table1, table2 empno city lowsal hisal grade
WHERE table1.col1 = table2.col1;
e.g. Consider the following tables PERSON and 110 Delhi 5000 10000 2
ORDERS 111 NCR 11000 13000 1
P_Id Last_Name First_Name City With respect to the tables given above write a
command to display the Employee names and the
1 Sharma Abhay Mumbai corresponding cities.
2 Gupta Mohan Delh (b) With respect to the tables given above , write
commands for the following :
3 Verma Akhil Mumbai
(i) To display the average salaries of all
employees who are not from Delhi.
TABLE : ORDERS (ii) To display, maximum salary from the
O_Id Order_No P_Id EMP table among employees whose date
is after 2014
1 10050 3
(iii) To find the count of employees who are
2 25000 3 from Delhi
3 5687 1 (iv) To display each employees name and
Grade.
4 45000 1
Sol :
5 35000 15
(a) SELECT EMP.ename, SALGRADE.city
To display the order numbers and corresponding
first names the command using equi join concept
FROM EMP, SALGRADE WHERE EMP.
is :
empno = SALGRADE.empno;
(b) (i) SELECT AVG(sal) FROM EMP t1,
SELECT ORDERS.Order_No, PERSON.
SALGRADE t2 WHERE t1.empno=t2.
First_Name FROM, ORDERS, PERSON WHERE
Empno AND NOT t2.city =“Delhi”;
ORDERS.P_Id = PERSON.P_Id;
(ii) SELECT MAX(sal) FROM EMP WHERE
or
Aggregate functions are those that work on a
date> “2014-12-31”;
(iii) SELECT COUNT(*) FROM EMP t1,
group of records to generate aggregate results.
Among the above, the aggregate functions are :
SALGRADE t2 WHERE t1.empno=t2.
COUNT() - This function counts the number of empno AND t2.city =“Delhi”;
(iv) SELECT ename, grade FROM EMP t1 ,
rows.
MAX() - Returns the maximum among the values
SALGRADE t2 WHERE t1.empno=t2.
in a column.
empno AND (sal BETWEEN lowsal
AVG() - Returns the average of the values in a
AND hisal);
field or column.
Page 5 Sample Paper 1 Computer Science Class 12
print(n,end=‘ ’)
print()
Section D
def main():
n=int(input(“Enter a number :”)) 31. G.R.K International Inc. is planning to connect
patterns(n) its Bengaluru Office Setup with its Head Office in
main() Delhi. The Bengaluru Office G.R.K. International
Inc. is spread across an area of approx. 1 square
30. A linear stack called status contains the following kilometres consisting of 3 blocks. Human
information : Resources, Academics and Administration. You
Phone number of Employee as a network expert have to suggest answers to
Name of Employee the questions (i) to (v) raised by them.
Write the following methods to perform given Note Keep the distances between blocks and
operations on the stack status : number of computers in each block in mind, while
(i) Push_element ( ) To Push an object providing them the solutions.
containing Phone number of Employee and
Name of Employee into the stack.
(ii) Pop_element ( ) To Pop an object from the
stack and to release the memory.
or
Write a function to pop an element from a stack
s using a function stackpop().
Sol :
def Push_element (Status, Top): Shortest distances between various blocks
phone_no = int (input (“Enter
phone number :”)) Human Resources to Administration 100 m
emp_name = input (“Enter employee Human Resources to Academics 65 m
name :”)
St = (phone_no, emp_name) Academics to Administration 110 m
Status.append (St) Delhi Head Office to Bengaluru 2350 km
Top =Top + 1 Office Setup
Number of computers installed at various blocks
return Top
def Pop_element (Status, Top) :
Slen = len (Status) Block Number of Computers
if (Slen <= 0) : Human Resources 155
print (“Status is empty”)
Administration 20
else :
phone_no, emp_name = Status.Pop() Academics 100
Top = Top – 1 Delhi Head Office 20
print(“Phone number %s and name (i) Suggest the most suitable block in the
%s Bengaluru Office Setup to host the server.
deleted” % (phoneLno, emp_name)) Give a suitable reason with your suggestion.
(ii) Suggest the cable layout among the various
return Top
or
blocks within the Bengaluru Office Setup for
def stackpop(s): connecting the blocks.
if Empty(s):
(iii) Suggest the placement of switch.
return “Underflow”
else : (iv) Suggest the most suitable media to provide
x=s.pop() secure, fast and reliable data connectivity
if len(s)==0: between Delhi Head Office and the Bengaluru
Top=None Office Setup.
else : (v) Expand the following
Top=len(s)–1 WAN
return x LAN
Page 7 Sample Paper 1 Computer Science Class 12
11. The_____clause with GROUP BY, can filter 17. Assertion (A) A python function can return more
groups from the query output. than one value to the calling function.
(a) WHERE (b) FILTER Reason (R) The return statement takes only a list
(c) HAVING (d) CHECK as parameter.
(a) Both A and R are true and R is the correct
Sol :
explanation of A.
(c) HAVING (b) Both A and R are true but R is not the
correct explanation of A.
12. Given a list L= [6,12,9,40,2,1]. Which of the
(c) A is true but R is false.
following statements will arrange the list in
(d) A is false but R is true.
reverse order
(a) L.arrange() Sol :
(b) L.sort() (b) Both A and R are true but R is not the correct
(c) L.sort(reverse=True) explanation of A.
(d) L.sort(reverse=False)
18. Assertion (A) While opening a binary file the
Sol :
mode may not be specified.
(c) L.sort(reverse=True) Reason (R) The open function for file opening
by default takes the mode parameter as rb for
13. Which method returns the next row from the
binary files, if no mode is specified.
result set as tuple?
(a) Both A and R are true and R is the correct
(a) fetchone( ) (b) fetchmany( )
explanation of A.
(c) fetchall( ) (d) rowcount
(b) Both A and R are true but R is not the
Sol : correct explanation of A.
(a) fetchone() (c) A is true but R is false.
(d) A is false but R is true.
14. An alternate key can be
Sol :
(a) only 1 in a table.
(b) a table can have maximum 2 alternate keys. (a) Both A and R are true and R is the correct
(c) a table can have at most 3 alternate keys. explanation of A.
(d) multiple in a relation.
Sol :
Section B
(d) Multiple in a relation
19. Find the output of the following code :
15. Which statement of SQL provides statements for
manipulating the database objects?
i=1
(a) DDL (b) DML
while(i<5):
(c) DCL (d) TCL
print(i)
i = i*2
Sol :
Sol :
(b) DML (Data Manipulation Language)
Page 3 Sample Paper 1 Computer Science Class 12
L1=[] Sol :
L2=[] (a) (i) SELECT NAME FROM STUDENT WHERE
for w in s.split(‘ ’): STREAM =‘COMPUTER’;
if w[0] in ‘aeiou’: (ii) SELECT COUNT(*) FROM STUDENT
L1.append(w) WHERE SEX = ‘F’
elif w[0] in ‘AEIOU’: (iii) SELECT STREAM, COUNT(*) FROM
L2.append(w) STUDENT GROUP BY STREAM;
print(“List of words starting with (iv) SELECT NAME, CITY FROM STUDENT,
lowercase vowels”, L1) ADDRESS WHERE STUDENT. AID =
print(“ List of words starting ADDRESS. AID;
with uppercase vowels”, L2) (b) SHOW TABLES;
def main():
counts(“A quick black elephant 29. Write a program to calculate the sum and mean
enters Into a jungle”) of the elements which are entered by user.
Sol :
main()
28. (a) Write SQL commands (i) to (iv) for the list1 = list()
following tables : sum = 0
num = int(input(“Enter the size of
TABLE : STUDENT
the list:”))
S NAME STREAM FEES AGE SEX AID
print(“Enter the number:”)
NO
for i in range (int(num)):
1 ARUN COMPUTER 750.00 17 M A1
l = int(input(“ ”))
KUMAR
list1.append(int(l))
2 DIVYA COMPUTER 750.00 18 F A2
sum = sum + list1[i]
JENEJA
mean = sum/num
3 KESHAR BIOLOGY 500.00 16 M A2
MEHRA
print(“Sum = ”, sum)
print(“Mean = ”, mean)
4 HARISH ENG. DR 350.00 18 M A1
SINGH
30. Write the Push operation of stack containing
5 PRACHI ECONOMICS 300.00 19 F A3 person names. Notice that the name should only
6 NISHA COMPUTER 750.00 15 F A3 accept characters, spaces and period (.) except
ARORA digits. Assume that Pname is a class instance
7 DEEPAK ECONOMICS 300.00 16 M A1 attribute.
KUMAR or
8 SARIKA BIOLOGY 500.00 15 F A1 Find the final contents of a stack that encounters
VASWANI the following tokens.
Assume that an operand is pushed to stack and
TABLE: ADDRESS a binary operator pops two operands from stack
and pushes the result to the stack.
AID City
100,8,3,*,50,2,+,+,*
Al Jamshedpur
Sol :
A2 Kolkata
def insert():
A3 Mumbai name_pattern = re.compile
(i) List the name of all the students, who (r “[A-Za-zs.]”)
have taken stream as COMPUTER. while True :
(ii) To count the number of female students. n = input (“Enter name:”)
(iii) To display the number of students stream while name_pattern. search (n) :
wise. print (“Invalid name”)
(iv) To display names of the students with print (“Enter name correctly”)
corresponding cities. n = input( )
(b) Write the command to display all the tables Sname. append (n)
in the database. c = input (“Enter more name
Page 6 Sample Paper 1 Computer Science Class 12
<y/n>”).upper ( )
Administrative Faculty Studio 120
if (c!=‘y’):
Building Building
break
or Finance Building Faculty Studio 70
Building
Scanned Operation Stack status
Elements Expected computers to be installed in each
building
100 Push 100
8 Push 100, 8 Buildings Computers
3 Push 100, 8, 3 Administrative Building 20
* Pop twice 8 * 3 = 24 100, 24 Finance Building 40
50 Push 100, 24, 50 Faculty Studio Building 120
2 Push 100, 24, 50, 2 (i) Suggest the most appropriate building, where
EPG should plan to install the server.
+ Pop twice 50 + 2 = 100, 24, 52 (ii) Suggest the most appropriate building to
52 building cable layout to connect all three
+ Pop twice 24 + 52 100, 76 buildings for efficient communication.
= 76 (iii) Which type of network out of the following is
* Pop twice 100 * 76 7600 formed by connection the computers of these
= 7600 three buildings?
Output 7600 (a) LAN (b) MAN (c) WAN
(iv) Write the difference between LAN and MAN.
(v) Expand the following
(a) WAN (b) MAN
Section D
Sol :
31. Expertia Professional Global (EPG) in an online (i) EPG should install the server in the Faculty
corporate training provider company for IT Studio Building as it has maximum number
related courses. The company is setting up their of computers.
new campus in Mumbai. You as a network expert (ii)
have to study the physical locations of various
buildings and the number of computers to be
installed. In the planning phase, provide the best
possible answers for the queries (i) to (v) raised
by them.
Physical locations of the buildings of EPG
A CSV file Bikes.csv stores details of bikes From: 0 - Beginning of the file
with their brand names, cc and cost. 1 - Current Position
Record structure of Bikes.csv 2 - End of the file
BID Bname Brand Cost Program :
(b) SearchBike(bikeid) : To open the file Bikes. import pickle
csv and display details of the bike whose def PutBike():
from id is supplied as the parameter to the f=open(“Bikes.csv”, “ab”)
function. ans=‘y’
Sol :
bid=“”
bname=“”
ten() method tells you the current position of brand=“”
cursor within the file. cost=0.0
Syntax file_object.tell() while ans==‘y’:
Program: bid=input(“Enter bike id.”)
import pickle bname=input(“Enter bike name ”)
def AddRegistration(): brand=input(“Enter brand : ”)
f=open(“Registration.dat”, “ab”) cost=float(input(“Enter cost”))
ans=‘y’ blst=[bid, bname, brand,cost]
rno=“” pickle.dump(blst,f)
sname=“” ans=input(“Continue(y/n)”.)
class=“” f,close()
Nos=0 def SearchBike(bikeit):
while ans== ‘y’: f=open(“Bikes:csv,” “rb”)
rno=input(“Enter registration while True:
no..”) try:
sname=input(“Enter student blst=pickle.load(f)
name ”) if blst[0]=bikeid:
class=input(“Enter class”) print(blst)
Nos=int(input(“Enter number of break
subjects :”)) except EOFError:
reglst=[rno,sname,class,Nos] print(“No such bike!!!”)
pickle.dump(reg1st.f) f.close.()
ans=input(“Continue(y/n)”)
f.closec()
def CountRegistrations():
f=open(“Registration.dat”, “rb”)
Section E
count=0
34. Consider the following table ORDERS :
try:
while True: TABLE : ORDERS
phone1st=pickle.load(f)
O_Id OrderDate OrderPrice Customer
count+=1
print(“Number of registrations 1 2008/11/12 1000 Hansen
:”, count) 2 2008/10/23 1600 Nilsen
except EOFError:
break: 3 2008/09/02 700 Hansen
f.close() 4 2008/09/03 300 Hansen
AddRegistration() 5 2008/08/30 2000 Jensen
CountRegistrations()
or 6 2008/10/04 100 Nilsen
seek() method can be used to changes the current (i) Write a statement to create the above table.
file position (ii) Write a command to change the width of
Syntax: Fileobject.seek(offseff[, from]) Customer column to varchar(30)
Offset: number of bytes to be moved. (iii) Write statements to :
Page 9 Sample Paper 1 Computer Science Class 12
END
Page 1 Sample Paper 1 Computer Science Class 12
10. The.........command can be used to remove all 16. The first integrity rule for relational databases
records of a table along with the table structure. ensures that_____
(a) DELETE TABLE (a) Primary key is unique
(b) DROP TABLE (b) Foreign key is unique
(c) REMOVE TABLE
(d) None of these (c) Primary key is unique and NOT NULL
11. What is the output of the following code? (c) Primary key is unique and NOT NULL
>>> a = 10
Directions (Q.Nos. 17-18) are Assertion and
>>> b = 2
Reason based questions.
>>> print(a + 10 * 2 + b)
(a) 32 (b) 22 17. Assertion (A) User-defined functions must stay in
(c) 40 (d) 80 a Python module.
Sol : Reason (R) Each user-defined function must stay
in a module ,which is linked to a folder where all
(a) 32 the user defined functions of the module stay.
12. Which function is used to generate a sequence of (a) Both A and R are true and R is the correct
numbers overtime? explanation for A.
(a) range() (b) len() (b) Both A and R are true but R is not the
(c) limit() (d) lim() correct explanation for A.
Sol : (c) A is true but R is false.
(a) range() (d) A is false but R is true.
print(i)
Section B i=i*2
24. Name the tokens that are available in Python. 26. Consider the tables FAMILY and Occupation:
or TABLE FAMILY
Find the syntax error in the following program
No Name Female Male Income Occup-
and underline after correct them. Members Members ationId
90 = w
1 Mishra 3 2 7000 O1
while(w > 60)
2 Gupta 4 1 50000 O2
print(w)
w = w – 50 3 Khan 6 3 8000 O2
4 Chaddha 2 2 25000 O1
Sol :
5 Yadav 7 2 20000 O3
Python has the following tokens
(i) Identifiers 6 Joshi 3 2 14000 O2
(ii) Keywords 7 Maurya 6 3 5000 O1
(iii) Punctuators 8 Rao 5 2 10000 O3
(iv) Literals
(v) Operators
Table : OCCUPATION
or
Correct code is Occupationld Type
w = 90 O1 Service
whi1e(w>60):
O2 Business
print(w)
w = w – 50 O3 Mixed
(a) To display Family name , corresponding
25. Explain the use of ORDER BY clause.
occupation and income where male members
or
are more than 2.
What are DDL and DML?
(b) Write SQL queries for statements (i) to (iv)
Sol : based on tables FAMILY and Occupation.
The ORDER BY keyword is used to sort the (i) To select all the information of family,
result set along a specified column with the whose Occupation is Service.
SELECT command. (ii) To list the name of family, where female
The ORDER BY keyword sorts the records in members are more than 3.
ascending order by default. If you want to sort (iii) To list all names of family with income in
the records in a descending order, you can use the ascending order.
DESC keyword. (iv) To count the number of family, whose
Syntax income is less than 10000.
SELECT column_name(s) Sol :
FROM table_name
(a) SELECT Name, Type,Income FROM
ORDER BY column_name(s) ASC/DESC;
FAMILY F, OCCUPATION 0 WHERE
or
F.Occupationld= 0.0ccupationID
DDL (Data Definition Language) is a part of
where MaleMembers>2;
SQL, which provides commands for creating,
(b) (i) SELECT * FROM FAMILY
altering and dropping the tables. Different DDL
F,OCCUPATION 0 WHERE
commands are CREATE, ALTER, DROP and
F.OccupationId=0.0ccupationId
RENAME.
= ‘Service’;
DML (Data Manipulation Language) is a part
(ii) SELECT Name FROM FAMILY WHERE
of SQL, which provides commands for inserting,
FemaleMembers > 3;
deleting and updating the information in a
(iii) SELECT Name, Income FROM FAMILY
database. Different DML commands are SELECT,
ORDER BY Income;
UPDATE, INSERT.
(iv) SELECT COUNT(*) FROM FAMILY
WHERE Income < 10000;
Page 5 Sample Paper 1 Computer Science Class 12
tid=“” ”))
st=“” clst=[cno,bd,kms,cost]
type=“” pickle.dump(clst,f)
pmoney=0.0 ans=input(“Continue(y/n)”)
while ans==‘y’: f.close()
tid=input(“Enter ticket id”) def CarReport():
st=input(“Enter state name ”) f=open(“car.dat ”,“rb”)
type=input(“Enter ticket type while True:
: ”) try:
pmoney=float(input(“Enter clst=pickle.load(f)
prizemoney ”) if int(tlst{2] > 100000):
tlst=[tid, st, type,pmoney] print(clst)
if st=State: break
pickle.dump(tlst,f) except EOFError:
ans=input(“Continue(y/n)”) print(“No such ticket!!!”)
f.close() f.close()
def TicketSearch(tid): AddCardata()
f=open(“lottery.dot”,“rb”) CarReport()
while True:
try:
tlst=pickle.load(f) Section E
if tlst[0]==tid:
print(tlst) 34. Consider the following table FLIGHTS :
break
except EOFError; TABLE : FLIGHTS
print(“No such ticket!!!”) FL_NO STARTING ENDING NO_ NO_
f.close() FLIGHT STOPS
AddBuyers(State) IC301 MUMBAI DELHI 8 0
TicketSearch(tid) IC799 BENGALURU DELHI 2 1
or
MC101 INDORE MUMBAI 3 0
Text Files Binary Files IC302 DELHI MUMBAI 8 0
1 It is capable to It is capable to AB812 KANPUR BENGALURU 3 1
handle textual data. handle large file. IC899 MUMBAI KOCHI 1 4
2 It consists of series It consists of data AM501 DELHI TRIVANDRUM 1 5
of lines of a set of with a specific
MU499 MUMBAI MADRAS 3 3
letters, numbers or pattern without any
IC701 DELHI AHMEDABAD 4 0
symbols (String) delimiter.
Program: (i) The command to create the table was written
import pickle as :
def AddCardata(): Create table FLIGHTS( FL_NO integer,
f=open(“car.dat”, “wb”) STARTING char(20), ENDING char(30),
ans=‘y’ NO_FLIGHT integer, NO_STOPS integer);
cno=“” What is wrong with command ?
bd=“” (ii) What is the cardinality of the table ?
kms=0.0 (iii) Which functions will be used to :
cost=0.0 (a) Display total number of flights .
while ans==‘y’: (b) Display number of flights whose FL_NO
cno=input(“Enter car number :”) starts with IC
bd=input(“Enter brand name : ”) (option for part (iii) only)
kms=float(input(“Enter kilometers Write function names to :
: ”)) (a) Show the average Number of stops.
cost=float(input(“Enter cost : (b) Show the maximum number of stops.
Page 10 Sample Paper 1 Computer Science Class 12
Sol :
(i) Create table FLIGHTS( FL_NO varchar(10),
STARTING char(20), ENDING char(30) ,
NO_FLIGHT integer , NO_STOPS integer);
(ii) 9 Cardinality is the number of tuples or
rows in a table.
(iii) (a) SUM()
(b) COUNT()
or
(a) AVG()
(b) MAX()
END