XII COMPUTER SCIENCEdobbs
XII COMPUTER SCIENCEdobbs
[P.T.O.]
AS-07 2
(a) ast#ba (b) ast#bal
(c) last#ba (d) ast#ball
3 Evaluate the following expression:
16 - (4 + 2) * 5 + 2**3 * 4
(a) 54 (b) 46 (c) 18 (d) 32 1
4 Select the correct output of the code: 1
Text = “Python Programming”
print(Text.split(‘P’)
(a) [‘ython’, ‘rogramming’] (b) [‘ ‘, ‘ython ’, ‘rogramming’]
(c) [‘ ‘, ‘ython‘, ‘programming’] (d) [‘python’, ‘rogramming’]
5 What will be the output of the following code snippet:
str = ‘Welcome to Python world”
print(str[: : -3]) 1
6 Which of the following will give an error in Python for a tuple t=(4,
‘a’, 7.8)
(a) print(sum(t)) (b) t=(1,2,3)
(c) a,b,c = t (d) print(len(t)) 1
7 If mdict is a dictionary as defined below, then which of the following
statements will raise an exception? 1
mdict = {‘red’: 100, ‘black’: 200, ‘white’: 300}
(a) mdict.get(300) (b) mdict[‘red’]=20
(c) print(mdict[‘black’, ‘white’]) (d) print(str(mdict))
8 Predict the output: 1
L = [23,4,7,12,2]
L1 = L. sort ()
L. insert (2,16)
print (L, ‘&’, L1)
(a) [2,4,7,12,16,23] & [2,4,7,12,23]
(b) [2,4,16,7,12,23] & [2,4,16,7,12,23]
(c) [2,4,7,12,16,23] & None
[P.T.O.]
3 AS-07
(d) None of these
9 Predict the output for the following code snippet: 1
t = 4,
print(type(t))
(a) <class ‘int’> (b) <class ‘tuple’>
(c) No output (d) error
10. The syntax of seek () is: 1
file_object.seek (offset [, reference point])
What is the default value of reference_point?
(a) 0 (b) 1 (c) 2 (d) 3
11 State whether the following statement is True or False: 1
“Every syntax error is an exception but every exception cannot be
a syntax error.”
12. Write the output of the following Python code: 1
a = 20
def call (x):
global a
x+ = a
return x
x = 15
print(call (30), end= ‘$’)
(a) 35$ (b) 45$
(c) 50$ (d) 65$
13 Write the SQL query to add a primary key to an existing column
‘ADNO’ in the table ‘SRecord’. 1
14. Fill in the blank: 1
__________clause is used with SELECT statement to display data
in a sorted form with respect to a specified column.
15 Fill in the blank: 1
____________ is a number of tuples in a relation.
[P.T.O.]
AS-07 4
(a) Attribute (b) Degree
(c) Domain (d) Cardinality 1
16 Which SQL statement do we use to find out the total number of
records present in the table ORDERS? 1
(a) Select * from ORDERS;
(b) Select count(*) from ORDERS;
(c) Select find(*) from ORDERS;
(d) Select sum(*) from ORDERS;
17 What does HTTPS stand for?
(a) Hyper Text Protocol Secure
(b) Hypertext Transfer Protocol Secure
(c) Hidden Text Transfer Protocol Station
(d) Hypertext Transfer Protocol Station 1
18 Which of the following options is the correct unit of measurement
for network bandwidth?
(a) KB (b) bit
(c) Hz (d) Km 1
19 Fill in the blank:
TCP/IP stands for ____________________ 1
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 explanation for A
(C) A is True but R is False
(D) A is False but R is True
20 Assertion (A) : To use a function from a particular module, we
need to import the module.
Reason (R) : import statement can be written anywhere in the
program, before using a function from that module. 1
21 Assertion(A) : In SQL, the aggregate function AVG() calculates the
average value on a set of values and produce a single result.
[P.T.O.]
5 AS-07
Reason(R) : The aggregate functions are used to perform some
fundamental arithmetic tasks such as Min(), Max(), Sum() etc…1
SECTION-B ( 7 X 2=14 MARKS)
22 Mithilesh has written a code to input a number and evaluate its
factorial and then finally print the result in the format: “The factorial
of the <number> is <factorial value>” His code is having errors.
Rewrite the correct code and underline the corrections made.
f = 0
num = input(“Enter a number: ”)
n = num
while num > 1 :
f = f * num
num - = 1
else :
print (“The factorial of: ”, num , “is”, f) 2
23 Predict the output of the following: 2
for i in range (1, 15, 2):
temp = i
if i % 3 = = 0:
temp = i + 1
elif i % 5 = = 0:
continue
elif i = = 11:
break print(temp, end = ‘$’)
24 If L = [3,5,2,7,8,12,2,19] and L1 = [4,6,3,2,7,12,9] then 2
(i) (A) Write a statement to merge both the lists.
OR
(B) Write a statement to sort the elements in place of list L.
(ii) (A) Write a statement to get a new list SL with the elements
of L1 in descending order.
OR
[P.T.O.]
AS-07 6
(B) Write a statement to insert the last element of list L1 in the
list L at 5th index.
25 Identify the correct output(s) of the following code. Also write
the minimum and the maximum possible values of the variable
b.
import random
a=”Wisdom”
b=random.randint(1,6)
for i in range(0,b,2):
print(a[i],end=’#’)
(A) W# (B) W # i #
(C) W # s # (D) W # i # s #
26 What is the difference between primary key and alternate key? Give
example of each. 2
27 (i) (A) Write the command to add a column Percentage in the table
Marks. Where the data should be entered as decimal number i.e. 78.3
OR
(B) Write the constraint that will provide value to a column if no
value is inserted in that column.
(ii) (A) Write the command to change the name of a column from
Comm to Commission in the table Product.
OR
(B) Write the constraint that will allow null value but not duplicate
values in the column of a table.
28 Write the full form of the following: 2
(i) SMTP (ii) VOIP
SECTION-C ( 3 X 3 = 9 MARKS)
29 (A) Write a function uld_count() that will display the counting of all
the upper case alphabets, lower case alphabets and digits from a
text file “Para.txt”. 3
[P.T.O.]
7 AS-07
For ex – if Para. txt contains the following content
He lives in AB-66, AB Type Quarters.
Then the function should display:
Upper case alphabets – 7
Lower case alphabets – 18
Digits - 2
OR
(B) Write a method/function countwords() in Python to read
contents from a text file ‘DECODE.TXT’ to count and return
the occurrence of those worlds which are having 5 or more
characters.
For ex -if DECODE.TXT content is :
These days I am reading a motivational book.
The method/function should display
The words having 5 or more characters are 3.
30 (A) A dictionary, d_city contains the records in the following format:
{state:city} 3
Define the following functions with the given specifications:
(i) push_city(d_city) : It takes the dictionary as an argument
and pushes all the cities in the stack CITY whose states are
of more than 4 characters.
(ii) pop_city(): this function pops the cities and displays “Stack
empty” when there are no more cities in the stack.
(iii) peep(d_city) : This function displays the topmost element of
the stack without deleting it. If the stack is empty the function
should display ‘None’.
OR
(B) You have a stack named BooksStack that contains records of
books. Each book record is represented as a list containing
book_title, author_name, and publication_year. Write the
following user-defined functions in Python to perform the
specified operations on the stack BooksStack:
[P.T.O.]
AS-07 8
(I) push_book(BooksStack, new_book): This function
takes the stack BooksStack and a new book record
new_book as arguments and pushes the new book
record onto the stack.
(II) pop_book(BooksStack): This function pops the
topmost book record from the stack and returns it. If the
stack is already empty, the function should display
“Underflow”.
(III) peep(BookStack): This function displays the topmost
element of the stack without deleting it. If the stack is
empty, the function should display ‘None’.
31 Consider the following table:
TABLE : RENT_CAB
Vcode VName Make Color Charges
101 Big car Carus White 15
102 Small Car Ploestar Silver 10
103 Family car Windspeed Black 20
104 Classic Studio White 30
105 Luxury Trona Red 9
Based on the given table, write SQL queries for the following:
(A)
(i) Count the number of cars of different colors.
(ii) Display all the details in the descending order of charges.
(iii) Display the vcode, vname of the cars whose make has letter
‘o’ in their name.
OR
(B) (i) Increase the charges of all the cabs by 10%.
(ii) Delete all the cabs whose maker name is ‘Carus’
(iii) Display the sum of charges of all cars color-wise.
SECTION-D ( 4 X 4 = 16 MARKS)
[P.T.O.]
9 AS-07
32 (A) (i) Explain Catching exceptions using try and except block.
(ii) Give an example code to handle ZeroDivisionError using try
and except block. The code should display the message
“Denominator can’t be zero” in case of ZeroDivisionError
exception, and the message “Some other error occurred” in
case of any other exception.
OR
(B) (i) When is IOError exception raised in Python?
(ii) Give an example code to handle IOError using try and except
block. The code should display the message “File not found”
in case of IOError exception, and the message “Some other
error occurred” in case of any other exception. 4
33 Mr. Mahesh is a Python programmer working in a school. He has
to maintain the records of the sports students. He has created a
csv file named sports.csv to store the details. The structure of
sports.csv is :[sport_id, competition, prize_won]
Where sport_id is sport id (integer)
Competition is competition name (string)
Prize_won is (“Gold”, “Silver”, “Bronze”)
Mr. Mahesh wants to write the following user defined functions:
Add_details(): to accept the details of student and add to a csv
file, “sports.csv”.
Count_Medal(): to display the name the competitions in which
students have won “Gold_medal”.
Help him in writing the code of both the functions. 4
34 Consider the tables Games and Players given below: 4
TABLE GAMES
Gcode GameName Type Number Prize Money
101 Carrom Board Indoor 2 5000
102 Badminton Outdoor 2 12000
103 Table Tennis Indoor 4 Null
104 Chess Indoor 2 9000
105 Lawn Tennis Outdoor 4 25000
[P.T.O.]
AS-07 10
TABLE : PLAYERS
Pcode Name Gcode
1 Nabi Ahmad 101
2 Ravi Sahai 108
3 Jatin 101
4 Nazneen 103
Write SQL queries for the following:
(i) Display the game type and average number of games played
in each type.
(ii) Display prize money, name of the game and name of the
players from the tables games and players.
(iii) Display the type of games without repetition.
(iv) (A) Display the name of the games and prize money of those
games whose prize money is known.
OR
(B) To display the cartesian product of these two tables.
35 Sunil wants to write a function ADRecord() in Python to insert a
record and display the records of the items whose price is between
200 to 300 in the table named Stall in MySQL database named
Maintain .
The table Stall in MySQL contains the following attributes:
I_code: item code (integer)
I_name : name of item (string)
Quan : quantity of the item (integer)
Amount : price of item (integer)
Consider the following to establish connectivity between Python and
MySQL:
Username – Administrator
Password – market
Host – localhost
SECTION-E (2 X 5 = 10 MARKS)
36 Rakesh is working in an educational Institute. He needs to manage
the records of various students. For this he wants the following
[P.T.O.]
11 AS-07
information of each student to be stored:
Student_id – integer
student_Name – string
Father_name – string
Percentage – float
You, as a programmer of the institute, have been assigned to do
this job for Rakesh. Suggest:
(I) What type of file (text file, csv file, or binary file) will you use
to store this data? Give one valid reason to support your
answer.
(II) Write a function to input the data of a student and append it
in the file that you suggested in part (I) of this question.
(III) Write a function to read the data from the file that you
suggested in part (I) of this question and display the data of
all those students whose percentage is more than 85. 5
37 Logistic Technologies Ltd. is a Delhi based organisation which is
expanding its office set-up to Ambala. At Ambala office campus,
they are planning to have 3 different blocks for HR, Accounts and
Logistics related work. Each block has a number of computers,
which are required to be connected to a network for communication,
data and resource sharing.
Ambala Office
Logistics Block
[P.T.O.]
AS-07 12
Distance between various blocks/locations:
HR block to Accounts blocks 400 meters
Accounts block to Logistics block 200 meters
[P.T.O.]
3 AS-07
[P.T.O.]