0% found this document useful (0 votes)
389 views

ComputerScience SQP Set1 MS

Uploaded by

dewan school
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
389 views

ComputerScience SQP Set1 MS

Uploaded by

dewan school
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

SAMPLE QUESTION PAPER (THEORY)-I

CLASS: XII SESSION: 2024-25


COMPUTER SCIENCE (083)
Marking Scheme
Q.No. Section-A (21 x 1 = 21 Marks) Marks
1. State True or False: (1)
The Python interpreter handles logical errors during code execution.
Ans: False
2. Consider two tuples : tup1=(1,2,4,3) ; tup2=(1,2,3,4) (1)
What will the following statement print(tup1< tup2)
A) True B) False C) Error D) None of these
Ans: False
3. Which of the following statements are True.
a. [1,2,3,4]>[4,5,6] b. [1,2,3,4]< [1, 5, 2, 3]
c. [1, 2, 3, 4] >[1,2,0,3] d. [1,2,3,4]< [ 1, 2, 3, 2 ] (1)
A) a, b, d B) a, c, d C) b, c D) only d
Ans: b,c
4. ………..function will always return tuple of 3 elements. (1)
A) index( ) B) split( ) C) partition( ) D) strip( )
Ans: C) partition( )
5. Which of the following is the correct syntax of string slicing:
A) str_name[start:end] B) str_name[start:step] (1)
C) str_name[step:end] D) str_name[step:start]
Ans: A) str_name[start:end]
6. What will be the output of the following code? (1)
T= (‘C’,‘O’,’M’,’P’,’U’,’T’,’E’,’R’)
print(T[-2:-7:-2])
A) (’R’,’T’,’P’,’O’) B) (’E’,’U’,’M’) C) (‘O’,’M’,’P’) D) (’M’,’P’,’U’)
Ans: B) (’E’,’U’,’M’)
7. Which of the following statements are not correct: (1)
A. An element in a dictionary is a combination of key-value pair
B. A tuple is a mutable data type
C. We can repeat a key in dictionary
D. clear( ) function is used to deleted the dictionary.
A) A, B, C B) B, C, D C) B, C, A D) A, B, C, D
Ans: B) B, C, D
8. What will be the output of the following code snippet? (1)
a = {(1,2):1,(2,3):2}
print(a[(1,2)])
A) Key Error B) 1 C) {(2,3):2} D) {(1,2):1}
Ans: B) 1
9. An attribute in a relation is foreign key if it is the………….key in any other relation. (1)
(a) Candidate (b) Primary (c) Super (d) alternate
Ans: (b) Primary
10. Which statement will move the file pointer 10 bytes backward from current position? (1)
(a) f.seek(-10,0) (b) f.seek(10,0) (c) f.seek(-10,1) (d) None of the above
Ans: f.seek(-10,1)
11. State whether the following statement is True or False:
It is raised when the file specified in a program statement cannot be opened.
(a) SyntaxError (b) ValueError (c) IOError (d) KeyboardInterrupt (1)
Ans: (a) SyntaxError

Page: 1/11
12. What will be the output of the following code?
x=3
def myfunc():
global x
x+=2
print(x,end=’ ‘)
print(x,end=’ ‘)
myfunc() (1)
print(x,end=’ ‘)
(a) 3 5 5 (b) 5 5 5 (c) 5 3 5 (d) 3 3 5
Ans: (a) 3 5 5
13. In SQL, what is the use of IS NULL operator? (1)
Ans: IS NULL is a logical operator in SQL that allows you to exclude rows with missing
data from your results.
14. Abhay wants to remove the table STORE from the database MyStore. Which command (1)
will he use from the following:
a) DELETE FROM store; (b) DROP TABLE store;
c) DROP DATABASE mystore; (d) DELETE store FROM mystore;
Ans: (b) DROP TABLE store;
15. Which function is used to display the total number of records/cardinality from table in a (1)
database?
(a) sum(*) (b) total(*) (c) count(*) (d) return(*)
Ans: (c) count(*)
16. Which of the following types of table constraints will prevent the entry of duplicate rows? 1 (1)
(a) Unique (b) Distinct (c) Primary Key (d) NULL
Ans: (b) Distinct
17. Which of the following is NOT a standard Python exception? (1)
(a) KeyError (b) ValueException (c) IndexError (d) TypeError
Ans: (b) ValueException
18. Which transmission media is capable of having a much higher bandwidth (data capacity)? (1)
(a) Coaxial (b) Twisted pair cable (c) Untwisted cable (d) Fiber optic
Ans: (d) Fiber optic
19. Switch is a (1)
(a) Broadcast device (b) Uni-cast device
(c) Multi-cast device (d) None of the above
Ans: (b) Uni-cast device
Q20 and Q21 are Assertion(A) and Reason(R) based questions. Mark the correct
choice as:
(A) Both A and R are true and R is the correct explanation for A
(B) Both A and R are true and R is not the correct explanationfor A
(C) A is True but R is False
(D) A is False but R is True
20. Assertion (A): Default parameters are used in Python functions to specify values for (1)
arguments that are not explicitly passed by the caller.
Reasoning (R): This allows the function to have a default behaviour when the caller does
not provide a value for an argument.
Ans: (A)
21. Assertion (A): The BETWEEN operator in SQL is used to match a within a range of
values.
Reasoning (R): The BETWEEN operator can only be used with numerical values in SQL. (1)
Ans: (C) The values can be numbers, text, or dates

Page: 2/11
Section-B ( 7 x 2=14 Marks)
22. What is slicing? Write the output for the following: (2)
Str= “Computer Science”
(i) print(Str[-10:4]) (ii) print(Str[-10:-4])
Ans: (i) not output (ii) er Sci
23. What is an exception in Python? Write suitable example. (2)
Ans: An exception is an unexpected event that occurs during program execution.
Example:
L=['JAVA','PYTHON','C++','ASP','JSP']
try:
print(L[5])
except IndexError as e:
print(e)
24. If L1=[1,2,3,2,1,2,4,2, . . . ], and L2=[10,20,30, . . .], then
(Answer using built in functions only)
(I)
A) Delete 5th position value of the list L2.
OR (2)
B) Empty list L2
(II)
A) Write a statement to insert element 7 in 5th position of List L1
OR
B) Write a statement to reverse the elements of list L1.
Ans: (I) A) L2.pop(5) B) L2.clear( )
(II) A) L1.insert(5,7) B) L1.reverse()
25. What are the possible outcome(s) will get after execution of the following code? (2)
import random
lst=[‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
for i in range(3):
print(ord(random.choice(lst))+1,’@’, end= “”)
(a) 102@99@100@ (b) 98@99@98@ (c) 103@100@98 (d) 97@99@101@
Ans: Ans: (a), (b), (c)
26. Write a program to replaces elements having even values with its half and elements having
odd values with twice its value in a list.
eg: if the list contains
3, 4, 5, 16, 9
then rearranged list as
6, 2,10,8, 18
However, there are syntax and logical errors in the code. Rewrite it after removing all
errors. Underline all the corrections made.

Def rearranged(L):
L=[3, 4, 5, 16, 9]
for i in range(n):
if L[i] % 2 == 0:
L[i] =/ 2
else:
L[i] =/ 2
print (L)
Ans:
L=[3, 4, 5, 16, 9]
def rearranged(L):
for i in range(len(L)):

Page: 3/11
if L[i] % 2 == 0:
L[i]/=2
else:
L[i]/= 2
print (L)
rearranged(L)
27. A) List one advantage and one disadvantage of Ring topology.
Ans:
Advantages Disadvantages (2)
No Need for a Server Equipment Connection
OR
B) Expand the term MODEM. What is the use of MODEM?
Ans: The name modem means modulator demodulator. A modem connects our computer to
a standard phone line or to our cable, which allows us to send data or receive data.
28. (i) a) An attribute A of datatype varchar(20) has the value “Amit” . The attribute B of (2)
datatype char(20) has value ”Karanita” . How many characters are occupied in attribute
A ? How many characters are occupied in attribute B?
Ans: 4 characters are occupied in attribute A .
20 characters are occupied in attribute B
OR
b) While creating a table named “Employee”, Mr. Rishi got confused as which data type
he should choose for the column “EName” out of char and varchar. Help him in
choosing the right data type to store employee name. Give valid justification for the
same.
Ans: Varchar would be the suitable data type for EName column as char data type is a
fixed length data type while varchar is a variable length data type. Any employee‟s
name will be of variable length so it‟s advisable to choose varchar over char data
type.
Section-C ( 3 x 3 = 9 Marks)
29. A) A text file contains alphanumeric text (say an.txt). Write a program that reads this text
file and prints only the numbers or digits from the file.
Ans: (3)
fh=open(“python.txt","r")
rec=fh.read();
for a in rec:
if a.isdigit():
print(a,end=' ')
fh.close()
OR
C) Write a function remove_lowercase() that accepts two filenames, and copies all the
lines that do not start with a lowercase letter from the first file into the second.
Ans:
def Remove_Lowercase(input_file, output_file):
input_file = open(input_file, 'r')
output_file = open(output_file, 'w')
for line in input_file:
if line.strip() and line[0].isupper():
output_file.write(line)
input_file.close()
output_file.close()

input_file = 'file1.txt'
output_file = 'file2.txt'

Page: 4/11
Remove_Lowercase(input_file, output_file)
30. A) Julie has created a dictionary containing names and marks as key value pairs of 6
students. Write a program, with separate user defined functions to perform the following
operations:
● Push the keys (name of the student) of the dictionary into a stack, where the
corresponding value (marks) is greater than 75.
● Pop and display the content of the stack.
For example: If the sample content of the dictionary is as follows:
R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}
The output from the program should be: TOM ANU BOB OM
Ans:
R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}
N=[]
def PUSH(R,N): (3)
for i in R:
if R[i]>=75:
N.append(i)
def POP(N):
if N!=[]:
return N.pop()
else:
return None
def TRAVERSE(N):
if len(N)==0:
print("Empty Stack")
else:
for i in range(len(N)-1,-1,-1):
print(N[i])

PUSH(R,N)
TRAVERSE(N)

POP(N)
OR
(B) Write a program to create a Stack for storing only odd numbers out of all the
numbers entered by the user. Display the content of the Stack along with the largest
odd number in the Stack. (Hint. Keep popping out the elements from stack and
maintain the largest element retrieved so far in a variable. Repeat till Stack is empty)
Ans:
n=int(input("Enter the number of values: "))
stack=[]
for i in range(n):
num= int(input("Enter number: "))
if num%2!= 0:
stack.append(num)
largestNum = stack.pop()
while(len(stack)>0):
num= stack.pop()
if num>largestNum:
largestNum=num
print("The largest number found is: ",largestNum)
31. Predict the output of the following code:
def fun(s):
k=len(s)

Page: 5/11
m=" "
for i in range(0,k):
if(s[i].isupper()):
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
else: (3)
m=m+'bb'
print(m)
fun('school2@com')
Ans:
SCHOOLbbbbCOM
OR
Predict the output of the following code:
v=50
def display(n):
global v
v=25
if n%7==0:
v=v+n
else:
v=v-n
print(v,end="#")
display(20)
print(v)
Ans: 50#5
Section-D ( 4 x 4 = 16 Marks)
32. Write the characteristics of CSV files. (4)
Write a Program in Python that defines and calls the following user defined functions:
i) APPEND() – To add two records of book to a CSV file „BOOK.csv‟. Each record
consists of a list with field elements as bookid, bname and price to store book id, book name
and book price respectively.
ii) DISP() – To count and display the number of records in the following format. Books
above price 500 :
BookID Bname price
101 Computer Application 450
102 Computer Science 670
105 Informatics Practices 500
Ans:
Ans:
import csv
def APPEND ():
fw=open("Book.csv",'w',newline='')
Book=[]
writer=csv.writer(fw)
writer.writerow(['BookID', 'BName', 'Price'])
for i in range(5):
BookID=input("Book ID : ")
Bname=input("Book Name : ")
price=int(input("Price : "))
data=[BookID,Bname,price]
Book.append(data)
writer.writerows(Book)
fw.close()
def DISP():

Page: 6/11
fr=open("Book.csv",'r')
reader=csv.reader(fr)
print(reader)
count=0
next(reader)
for row in reader:
if int(row[2])>500:
print(row[0],row[1],row[2],sep='\t')
fr.close()
APPEND()
DISP()
33. Consider the tables BOOK and MEMBER Given table:
Table: BOOK
CODE BNAME TYPE
F101 The Priest Fiction
L102 German easy Literature
C101 Tarzan in the lost world Comic
F102 Untold story Fiction
C102 War heroes Comic
TABLE: MEMBER (4)
MNO MNAME CODE ISSUEDATE
M101 Raghav Sinha L102 2016-10-13
M103 Sarthak John F102 2017-02-23
M102 Anisha Khan C101 260-06-12
Write SQL queries for the following:
(i) To display all details from table MEMBER in descending order of ISSUEDATE.
Ans: Selcet * From Member order by Issuedate Desc;
(ii) To display the CODE and BNAME of all Fiction Type books from the table Book.
Ans: Select Code, Bname from Book, Member where Book.Code=Member.Code and
Book.Type= ‘Fiction’;
(iii) To display each Member name and corresponding Bookname.
Ans: Select Mname,Bname fron Member, Book where Book.Code=Member.Code;
(iv) To display Booknames, Member name and issue date for books of type 'Fiction'.
OR
Write the output of the queries (i) to (iv) based on the table, SALES given below:

i) SELECT DESIG FROM SALES WHERE NAME LIKE ‘%H’;


Ans:
DESIG
D3
D2
ii) SELECT DESIG, COUNT(*), MIN(SALES) FROM SALES GROUP BY DESIG
HAVING COUNT(DESIG)>1;
Ans:
DESIG COUNT(*) MIN(SALES)
D1 2 250000
D2 2 1250000
iii) SELECT NAME,SALES FROM SALES WHERE SALES BETWEEN 100000 AND

Page: 7/11
1000000;
Ans:
Name Sales
Y.P.SINGH 1300000
TINHA JAISWAL 1400000
GURDEEP SINGH 1250000
SIMI FAIZAL 1450000

iv) SELECT DESIG, SUM(SALES) FROM SALES GROUP BY DESIG;


Ans:
DESIG SUM(SALES)
D1 1475000
D3 1300000
D2 2650000
34. Consider the following MOVIE table and write the SQL queries based on it.
Table : Movie
MovieID MovieName Category ReleaseDate ProductionCost BusinessCost
001 Hindi_Movie Musical 2018-04-23 124500 130000
002 Tamil_Movie Action 2016-05-17 112000 118000
003 English_Movie Horror 2017-08-06 245000 360000
004 Bengali_Movie Adventure 2017-01-04 72000 100000
005 Telugu_Movie Action NULL 100000 NULL
006 Punjabi_Movie Comedy NULL 30500 NULL
a) Display all the information from the Movie table. (4)
Ans: Select * From Movie;
b) List business done by the movies showing only MovieID, MovieName and
Total_Earning. Total_Earning to be calculated as the sum of ProductionCost and
BusinessCost.
Ans: Select MovieID, MovieName, ProductionCost+BusinessCost as “Total Earning” From
Movie;
c) List the different categories of movies.
Ans: Select Distinct Category From Movie;
d) (i) Find the net profit of each movie showing its MovieID, MovieName and NetProfit.
Net Profit is to be calculated as the difference between Business Cost and Production
Cost.
Ans: Select MovieID, MovieName, BusinessCost- ProductionCost as “Net Profit” From
Movie;
35. Aarya has created a table named Emp in MySQL:
EmpNo – integer
EmpName – string
Age– integer
Salary – integer
Note the following to establish connectivity between Python and MYSQL:
• Username - root
• Password - tiger
• Host - localhost (4)
• The Emp table exists in a MYSQL database named company.
• The details of Emp table (EmpNo, EmpName, Age and Salary)
Aarya wants to display All Records of Emp relation whose age is greater than 55. Help
Aarya to write program in python.
Ans:
import mysql.connector
mydb= mysql.connector.connect(host= “localhost”, user= “root”, passwd= “tiger”,

Page: 8/11
database= “company”)
mycur=mydb.cursor()
mycur.execute(“Select * From Emp”)
data=mycur.fetchall()
for row in data:
print(row)
mycur.close()
mydb.close()
Q.No. SECTION E (2 X 5 = 10 Marks) Marks
36. A binary file "Book.dat" has structure [BookNo, Book_Name, Author, Price]. (5)
i. Write a user defined function createFile() to input data for a record and add to Book.dat.
ii. Write a function to increase price 100/- those Book name has ‘Computer Science’.
iii. Write a function countRec(Author) in Python which accepts the Author name as
parameter and count and return number of books by the given Author are stored in the
binary file "Book.dat".
Ans:
import pickle
#Program to write multiple record in binary file
def create():
fw=open("book.dat",'ab')
while True:
BookNo=int(input("Enter Roll No. :"))
Book_Name=input("Enter Name :")
Author=input("Enter Author : ")
Price=int(input("Enter Marks :"))
pickle.dump([BookNo, Book_Name, Author, Price],fw)
ch=input("Add more records? press y/n").lower()
if ch=='n': break
fw.close()
#Program to update record in binary file
def update():
fr=open("book.dat",'rb+')
r=input("Enter Book Name ")
found=False
try:
while True:
cPos=fr.tell()
rec=pickle.load(fr)
if rec[1]==r:
rec[3]=rec[3]+100 #int(input("Enter New Marks :"))
fr.seek(cPos)
pickle.dump(rec,fr)
found=True

except EOFError:
print("")
if found==False:
print("Recod Not found")
fr.close()
37. Bias Methodologies is planning to expand their network in India starting with three cities
in India to build infrastructure for research and development of their chemical products.
The company has planned to setup their main office in Pondicherry at three different
locations and have named their offices as Back Office, Research Lab and Development
Unit. The company has one more research office namely Corporate Unit in Mumbai. A

Page: 9/11
rough layout of the same is as follows:

(5)

Approximate distance between these offices is as follows:

In continuation of the above, the company experts have planned to install the following
number of computers in each of these offices.
(i) Suggest the kind of network required (out of LAN, MAN, WAN) for connection each
of the following office unit
(a) Research Lab and Back Office
(b) Research Lab and Development Unit
(ii) Which of the following devices will you suggest for connecting all the computers with
each of their office units?
(a) Switch/Hub (b) Modem (c) Telephone
(iii) Which of the following communication media, will you suggest to be procured by the
company for connecting their local office units in Pondicherry for very effective (high
speed) communications?
(a) Telephone cable (b) Optical fiber (c) Ethernet cable
(iv) Suggest a cable/wiring layout for connecting the company’s local office units located
in Pondicherry. Also, suggest an effective method/technology for connecting the
company’s office located in Mumbai.
(v) Suggest the most appropriate location of the server inside the Pandicharry campus.
Justify your choice.
Ans:
(i) The type of network between the Research Lab and the Back Office is LAN (Local Area
Network). The type of network between Research Lab and Development Unit is MAN
(Metropolitan Area Network).
(ii) The suitable device for connecting all the computers within each of their office units is
switch/hub.
(iii) For connecting the local office units in Pondicherry for very effective (high speed)
communication is optical fiber.
(iv) The cable/wiring layout for connection is as follows:

Page: 10/11
(v) Research Lab

Page: 11/11

You might also like