QP_CS_XII_Set2
QP_CS_XII_Set2
QP_CS_XII_Set2
a) JamesJamesJamesJamesJamesJames
b) JamesJamesJamesJamesJames
c) Error: invalid syntax
d) None
7. What will be the output of the following Python code snippet? (1)
total={}
def insert(items):
if items in total:
total[items] += 1
else:
total[items] = 1
insert('Apple')
insert('Ball')
insert('Apple')
print (len(total))
a) 3 b) 1 c) 2 d) 0
8. What will be the output of the following Python code? (1)
s="a@b@c@d"
a=list(s.partition("@"))
print(a)
b=list(s.split("@",3))
print(b)
a) [‘a’,’b’,’c’,’d’] b)[‘a’,’@’,’b’,’@’,’c’,’@’,’d’]
[‘a’,’b’,’c’,’d’] [‘a’,’b’,’c’,’d’]
c) [‘a’,’@’,’b@c@d’] d) [‘a’,’@’,’b@c@d’]
[‘a’,’b’,’c’,’d’] [‘a’,’@’,’b’,’@’,’c’,’@’,’d’]
10. Which of the following is not an exception handling keyword in Python? (1)
a) try b) except c) accept d) finally
11. What will be the output of the following Python code? (1)
a=10
b=20
def change():
global b
a=45
b=56
change()
print(a)
print(b)
a) 10 b) 45 c) 10 d) Syntax Error
56 56 20
12. Which device connects an organization's network with the outside world of the (1)
Internet?
a) Hub b) Modem c) Gateway d) Repeater
13. Which data type has a fixed length in the database. (1)
a)Varchar(5) b) Char(n) c) Longchar(n) d) None of the above.
14. What will be the output of the following Python code? (1)
def display(b, n):
while n > 0:
print(b,end="")
n=n-1
display('z',3)
a) zzz b) zz c) An exception is executed d) Infinite loop
15. Which of the following allows you to connect and login to a remote computer? (1)
a) SMTP b) HTTP c) FTP d) Telnet
18. Which of the following will you use in the following query to display the unique (1)
values of the column dept_name?
SELECT _________ dept_name FROM Company;
19. A Database Administrator needs to display the average pay of workers from each (1)
departments with more than five employees. Which SQL query is correct for this
task?
a) SELECT DEPT, AVG(SAL) FROM EMP WHERE COUNT(*) > 5 GROUP BY DEPT;
b) SELECT DEPT, AVG(SAL) FROM EMP HAVING COUNT(*) > 5 GROUP BY DEPT;
c) SELECT DEPT, AVG(SAL) FROM EMP GROUP BY DEPT WHERE COUNT(*) >5;
d) SELECT DEPT, AVG(SAL) FROM EMP GROUP BY DEPT HAVING COUNT(*)> 5;
20. Assertion(A): Python overwrites an existing file or creates a non- existing file (1)
when we open a file with ‘w’ mode.
Reason(R): a+ mode is used only for writing operations
21. Assertion ( A): In SQL, the aggregate function Avg() calculates the average value (1)
on a set of values and produces a single result.
Reason ( R): The aggregate functions are used to perform some fundamental
arithmetic tasks such as Min(), Max(), Sum() etc
Q No Section-B ( 7 x 2=14 Marks) Marks
23. Predict the output of the Python code given below: (2)
a=tuple()
a=a + tuple(“Python”)
print(a)
print(len(a))
b=(10,20,30)
print(len(b))
24. A) Consider the following list of elements and write Python statement to print (2)
the
output of each question.
elements=['apple',200,300,'red','blue','grapes']
i) print(elements[3:5])
ii) print(elements[::-1])
OR
B) Consider the following list exam and write Python statement for the following
questions:
exam=[‘english’,’physics’,’chemistry’,’cs’,’biology’]
i) To insert subject “maths” as last element
ii) To display the list in reverse alphabetical order
26. Rewrite the following code in python after removing all syntax error(s). (2)
Underline each correction done in the code.
25 = Num
WHILE Num<=100:
if Num=>50:
print(Num)
Num=Num+10
else
print(Num*2)
Num=Num+5
28. A) A table Employee has 8 columns but no row. Later, 8 new rows are inserted (2)
and 2 rows are deleted in the table. And another table Dept has 5 rows and 4
columns. What is the degree and cardinality of the Cartesian Product of tables
Employee & Dept? (Employee X Dept)
OR
B) Consider the following two commands with reference to a table, named
Employee, having a column named D_name:
(a) Select count(D_Name)from Students;
(b) Select count(*)from Students;
If these two commands are producing different results,
(i) What may be the possible reason?
(ii) Which command,(a)or(b),might be giving higher value?
29. A) The file “City.txt” stores the name of few selected cities with the Pincode. (3)
Write a function Display() to read data and display only those city with the
Pincode whose first letter is not a vowels.
Sample Output:
New Delhi 110005
Mumbai 400001
OR
B) The file “Name.txt” stores the name of all the students of Class XII. Write a
function “Count()” to read the records from the file. Count and display all the
uppercase and lowercase letters separately available in file.
30. A) Each node of a stack named CITY contained the following information: (3)
Pin code of a city
Name of city
Write the following user-defined functions in Python to perform the specified
operations on the stack CITY:
i) PUSH_CITY(CITY, new_city): This function takes the stack CITY and a
new city record new_city as arguments and pushes the new city
record onto the stack.
ii) POP_CITY(CITY): This function pops the topmost city record from the
stack and returns it. If the stack is already empty, the function should
display "Underflow".
iii) DISPLAY(CITY): This function takes the stack CITY and display all its
elements If the stack is empty, the function should display 'None'.
OR
B) Write the definition of a user-defined function `PUSH_NUM(L)` which accepts
a list of integers in a parameter `L` and pushes all those integers which are either
multiple of 3 or 5 from the list `L` into a Stack named `NUMBERS`. Write function
POP_NUM() to pop the topmost number from the stack and returns it. If the stack
is already empty, the function should display "Empty". Write function
DISP_NUM() to display all element of the stack without deleting them. If the stack
is empty, the function should display 'None'.
For example:
If the integers input into the list `L` are:
[4,10, 15, 8, 14, 12]
Then the stack `NUMBERS` should store:
[10, 15, 12]
31. Predict the output of the Python code given below: (3)
def product(L1,L2):
p=0
for i in L1:
for j in L2:
p=p+i*j
return p
LIST=[1,2,3,4,5,6]
l1=[]
l2=[]
for i in LIST:
if(i%2!=0):
l1.append(i)
else:
l2.append(i)
print(product(l1,l2))
OR
Predict the output of the Python code given below:
tuple1 = (31, 22, 43, 54 ,65)
list1 =list(tuple1)
for i in list1:
new_list = []
for j in range(i%10):
new_list.append(i%10)
new_tuple = tuple(new_list)
print(new_tuple, end="@")
print("")
Section-D ( 4 x 4 = 16 Marks)
Q No. Marks
32. Consider a Table LOANS: (4)
OR
34. Consider the following tables Stationary and Consumer. Write SQL commands for (4)
the statement (i) to (iv):
Table: Stationary
S_ID StationaryName Company Price
DP01 Dot Pen ABC 10
PL02 Pencil XYZ 6
ER05 Eraser XYZ 7
PL01 Pencil CAM 5
GP02 Gel Pen ABC 15
Table: Consumer
C_ID ConsumerName Address S_ID
01 Good Learner Delhi PL01
06 Write Well Mumbai GP02
12 Topper Delhi DP01
15 Write & Draw Delhi PL02
16 Motivation Banglore PL01
SECTION E (2 X 5 = 10 Marks)
Q No. Marks
36. A file “Grade.dat” has already been created with the record containing index (5)
number, name, marks and grade as sub-lists of the list. Later on, the user realised
that he has made wrong entry of the grades in all the records.
i) Define a function Update() to open the file in “rb+” mode to read and
update the grades in all the records as per the criteria mentioned
below:
Marks Grade
90 and above A
>=80 and <90 B
Else C
ii) Write a function to read the data from the binary file and display the data of
all those candidates who grade id ‘A’.
37. A company in Mega Enterprises has 4 wings of buildings in Mumbai Campus as (5)
shown in the diagram :