12_computer_science_sp_10_with_solution
12_computer_science_sp_10_with_solution
Maximum Marks: 70
Time Allowed: : 3 hours
General Instructions:
Section A
1. State true or false:
A given object may appear in a list more than once.
a) True
b) False
2. Aggregate functions are also known as
a) group functions
b) Add function
c) group method
d) sum function
3. Which method returns the next row from the result set as tuple?
a) fetchone()
b) rowcount
c) fetchall()
d) fetchmany()
4. are used to pass the value of a variable to a function.
a) Objects
b) Arguments
c) Parentheses
d) Classes
5. Protective covering that protects the optical fiber from outside environment is known as
a) Core
b) Jacket
c) Buffer
d) Cladding
6. To read the next line of the file from a file object infi, we use
a) infi.read()
b) infi.readlines()
c) infi.readline()
d) infi.read(all)
7. To reflect the changes made in the database permanently, you need to run <connection>. method.
a) done()
b) reflect()
c) commit()
d) final()
8. Which of the following join gives the intersection of two tables?
a) Inner join
b) Outer join
c) Equi join
d) None of these
9. Which of the following statement is incorrect in the context of pickled binary files?
a) pickle module is used for reading and writing objects in binary files.
b) dump() of the pickle module is used to write objects.
c) load() of the pickle module is used to read objects.
d) csv module is used for reading and writing objects in binary files.
10. Which of the following is the use of function in python?
a) Functions don't provide better modularity for your application
b) Functions are reusable pieces of programs
c) you can't also create your own functions
d) All of these
11. Which of the following is/are linear data structure(s)?
a) Stack
b) Array
c) All of these
d) Queue
12. What is the area of memory called, which stores the parameters and local variables of a function call?
a) an array
b) storage area
c) a stack
d) a heap
13. State true or false:
The cloud is a generic term used for Internet.
a) True
b) False
14. Which index number is used to represent last character of string?
a) 0
b) -1
c) n - 1
d) 1
15. Fill in the blanks:
SQL is running in all .
16. Which type of transmission media is the least expensive to manufacture?
a) Twisted pair cable
b) CAT cable
c) Coaxial
d) Fibre optic
17. Assertion (A): In Python, we need to specify the type of variable.
Reason (R): Python is a infer language and smart enough to get variable type.
a) Both A and R are true and R is the correct explanation of A.
b) Both A and R are true but R is not the correct explanation of A.
c) A is true but R is false.
d) A is false but R is true.
18. Assertion (A): In the case of w+, it overwrites the previous file if one exists.
Reason (R): In the case r+, it doesn't overwrite the previous file if one exists.
a) Both A and R are true and R is the correct explanation of A.
b) Both A and R are true but R is not the correct explanation of A.
c) A is true but R is false.
d) A is false but R is true.
Section B
19. Answer:
1. i. What is carrier wave? What is a modulated wave?
ii. Write two characteristics of Wi-Fi.
2. OR
i. Give one advantage and one disadvantage of optical fiber cable and coaxial cable used in communication.
20. Write Python code to create a table faculty with the following fields.
Id, LastName, FirstName, Locationid, phone, rank, startdate
Rank should be one of the following
ASSO, FULL, ASST, INST
21. What are immutable and mutable types? List immutable and mutable types of Python.
OR
first = 25
second = 30
for i in range (1, 3, 1):
print("Output 1 = ", first -3, "&" , second +5)
print("Output 2 = " , second +1,"&", first -5)
22. Answer:
1. Can one DB-API be used for all database types?
2. What does cursor.fetchall( ) method do?
23. Write a program that prints a table on two columns - table that helps converting miles into kilometres.
OR
Write a program printing a table with two columns that help convert pounds in kilograms.
24. What are the advantages of saving data in binary form and text form?
OR
Considering the following definition of dictionary MULTIPLEX, write a method in python to search and display all the
content in a pickled file CINEMA.DAT, where MTYPE key of the dictionary is matching with the value 'Comedy'.
MULTIPLEX = {'MNO' : , 'MNAME' : , 'MTYPE' : }
25. What will be the output of the following code sinppet and why?
# module calculate.py
"""This module will be imported"""
def sum ():
"""Prints sum of 10 and 5"""
b=5
a = 10
print "sum =",a + b
return
def diff():
"""Prints difference of 20 and 5"""
a = 30
b=5
print "Difference =", a - b
return
print "This will print something"
greet = "Hello!"
#Fun.py
import calculate
print calculate.greet
Section C
26. Answer:
1. Find the errors in following code and write the correct code.
s = [11, 13, 15]
for n in arange(len(s)):
tot = tot + s(n)
print(tot)
i. Underline the corrections.
ii. Write the reason! error next to it in the comment form.
2. Find the output of the given code.
27. Write a function that takes a sorted list and a number as an argument. Search for the number in the sorted list using
binary search.
28. What are DDL and DML?
OR
Table : Books
Book_Id Quantity_Issued
F0001 3
T0001 1
C0001 5
i. SELECT COUNT (DISTINCT Publishers) FROM Books.
ii. SELECT SUM(Price) FROM Books WHERE Quantity > 5.
iii. SELECT Book_Name, Author_Name FROM Books WHERE Price < 500.
iv. SELECT COUNT (*) FROM Books.
Section E
33. Granuda Consultants are setting up a secured network for their office campus at Faridabad for their day to day office and
web-based activities. They are planning to have connectivity between 3 buildings and the head office situated in Kolkata.
Answer the questions (i) to (iv) after going through the building positions on the campus and other details, which are
given below:
Number of Computers
Building "RAVI" 25
Table: CARDEN
Table: CUSTOMER
OR
Consider the following tables GAMES and PLAYER and answer the following parts of this question :
Table: GAMES
3 Jatin 101
4 Nazneen 103
Table: WORKERS
Table: DESIG
Table: WORKER
Solution
Section A
1. (a) True
Explanation: True, A given object may appear in a list more than once
2. (a) group functions
Explanation: group functions
3. (a) fetchone()
Explanation: fetchone()
4. (b) Arguments
Explanation: Arguments
5. (c) Buffer
Explanation: Core is the part through which light travels.
Cladding covers the core and reflects light back to it.
Buffer is the fiber protection.
Jacket is not in the context.
6. (c) infi.readline()
Explanation: readline() function reads a line from the file pointer position.
7. (c) commit()
Explanation: commit()
8. (a) Inner join
Explanation: Inner join
9. (d) csv module is used for reading and writing objects in binary files.
Explanation: csv module is used for reading and writing objects in binary files.
10. (b) Functions are reusable pieces of programs
Explanation: Functions are reusable pieces of programs. They allow you to give a name to a block of statements,
allowing you to run that block using the specified name anywhere in your program and any number of times.
11. (c) All of these
Explanation: All of these
12. (c) a stack
Explanation: Stack stores the parameters and local variables of a function call.
13. (a) True
Explanation: True
14. (b) -1
Explanation: -1
15. 1. servers
16. (a) Twisted pair cable
Explanation: Twisted pair cable is the least expensive transmission media.
17. (d) A is false but R is true.
Explanation: In Python, we don't need to specify the type of variable because Python is a infer, dynamically typed
language, and smart enough to get variable type.
18. (b) Both A and R are true but R is not the correct explanation of A.
Explanation: w+ mode opens the file to write and read both. It is different from r+ mode in the sense that it overwrites
the previous file if one exists whereas r+ doesn't overwrite the previously written file. r+ mode creates a new file if no
file exists.
Section B
19. Answer:
1. i. The high frequency wave whose characteristics are altered to superimpose message information, is the
carrier wave and after altering the characteristics, the new resultant wave is called the modulated wave.
ii. Characteristics of Wi-Fi
i. It is a wireless solution for getting connected to the Internet.
ii. It is for short range.
2. OR
i. Optical Fiber Cable:
Advantage: It is free of electrical noise and interference.
Disadvantage: It is an expensive communication medium.
Coaxial cable:
Advantage: It provides a cheap means of transporting multi-channel television signals around metropolitan
areas.
Disadvantage: When using coaxial cables over long distances, signal loss is a disadvantage.
20. import MySQLdb
db=MySQLdb.connect("localhost", "Fact", "Faculty24", "Instd")
cursor=db.cursor()
cursor.execute("DROP TABLE IF EXISTS FACULTY")
sql="""Create Table Faculty(Id Number(3) PRIMARY KEY, LastName CHAR(20) NOT NULL , FirstName
CHAR(30) NOT NULL , locationid Number(6) , phone char(10) , rank char(4) check (rank IN('ASSO', 'FULL',
'ASST', 'INST')), startdate DATE)"""
cursor.execute(sql)
db.close()
21. The immutable types are those that can’t be changed after it is created. In Python, the following types are immutable:
integers, floating-point numbers, Booleans, strings, tuples.
The mutable types are those whose values can be changed in place. Only three types are mutable in Python, these
are lists, dictionaries, and sets.
OR
Output
Output 1 = 22 & 35
Output 2 = 31 & 20
Output 1 = 22 & 35
Output 2 = 31 & 20
22. Answer:
1. No, You need to download separate DB-API for each database you need to access. It defines a standard interface for
Python database access modules.
2. It returns/fetches all (remaining) rows of a query result, in the form of a Python list.
23. for i in range(1, 10):
print(i, i * 1.6)
OR
for i in range(1, 10):
print(i, i * 0.454)
24. i. The binary files store the data in pure binary bytes form and hence can be used on any machine/hardware with
appropriate software. There are no internal conversions added to data such as newlines etc. Binary files require
appropriate software in order to be read and decoded. The machine takes less time to process binary files.
ii. A text file is a computer file that is structured as a sequence of lines of electronic text. The text files store the data in
human readable text format. These have some internal conversions like newlines(\n) etc. Text files are human
readable but are not portable enough.
OR
def Search():
file = open ('CINEMA.DAT', 'rb')
try:
while True:
MULTIPLEX = pickle.load(file)
if MULTIPLEX['MTYPE']=="Comedy":
print(MULTIPLEX)
except EOFError:
file.close()
25. Output of the code is:
This will print something.
Hello!
When we import module, its main program is executed. Therefore, first the statement print "This will print something" is
executed and then print calculate.greet is executed. The function sum() and diff() are not called from Fun.py file, so they
are not executed in the code.
Section C
26. Answer:
1. s = [11, 13, 15]
tot = 0 # tot must be defined before being used
for n in range(len(s)): # built-in function is range() not arange()
tot = tot + s[n] #incorrect indentation and
# s is a list; to access its elements
# square brackets are used
2. P
R
O
G
R
A
M
27. def binary_search(sorted_list, number):
low = 0
high = len(sorted_list)
found = False
while (low < high) and found = False:
mid = int(low+high/2)
if sorted_list[mid] == number:
print ("Number found at",mid)
found = True
break
elif sorted_list[mid] == number:
low = mid + 1
else:
high = mid -1
if low >= high:
print ("Number not found")
max_range = input("Enter Count of numbers:")
numlist = []
for i in range(0, max_range):
numlist_append(input("Enter number : "))
numlist.sort()
print ("Our list : ", numlist)
number = input("Enter the number")
binary_search(numlist, number)
28. Both DDL and DML are SQL components.
Data Definition Language (DDL) statements are used to create the structure of a table, modify and remove the existing
table. Some of the DDL statements are CREATE TABLE, ALTER TABLE and DROP TABLE
Data Manipulation Language (DML) statements are used to access and manipulate data in existing tables. The common
DML statements are SELECT, UPDATE, DELETE and INSERT.
OR
35 12
iii. 5
iv. SX4
C Class
OR
i. 2
Sam 75000
Manila 70000
George 75000
ii. COUNT(DISTINCT DESIGNATION)
4
Salesman 60000
iv. Error in question - there are no Benefits and Designation columns in table WORKERS. If we assume
and change the table as DESIG for this query, output will be 15000.
2. OR
i. The ORDER BY clause of SQL SELECT statement allows to sort the data of result set. The GROUP BY
clause of SQL SELECT statement allows to create summarized results of grouped data from table.
ii. i. SELECT * FROM
WORKER ORDER BY DOB DESC;
ii. SELECT NAME, DESIG
FROM WORKER
WHERE PLEVEL IN ('P001', 'P002') ;
iii. SELECT * FROM WORKER
WHERE DOB BETWEEN '19-JAN-1984' AND '18-JAN-1987' ;
iv. INSERT INTO WORKER
VALUES(19, 'Daya Kishore', 'Operator' , 'P003' , '19-Jun-2008' , '11-Jul-1984') ;