12 Comp

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

ABU DHABI INDIAN SCHOOL – BRANCH 1, AL WATHBA

HALF YEARLY EXAMINATION - 2022-2023


GRADE: XII DIV: MAX.MARKS: 70
SUB: COMPUTER SCIENCE(083) TIME: 3 Hrs.
NAME OF THE STUDENT/EXAM NO: DATE: 14.10.2022
General Instructions:

• This question paper contains five sections, Section A to E.


• All questions are compulsory.
• Section A have 18 questions carrying 01 mark each.
• Section B has 07 Very Short Answer type questions carrying 02 marks each.
• Section C has 05 Short Answer type questions carrying 03 marks each.
• Section D has 03 Long Answer type questions carrying 05 marks each.
• Section E has 02 questions carrying 04 marks each. One internal choice is given in Q34 against part iii only.
• All programming questions are to be answered using Python Language only.

SECTION A
1. What types of objects can be used as keys in dictionaries? 1
i. Mutable ii. Immutable iii. None of these
2. If a=2**2**3, then print(a) will be 1
i. 64 ii. 12 iii. 256
3. Identify the invalid identifiers from the following:- 1
i. Final_Exam ii. percentage% iii.Class -12 iv.IN
4. Given list L1=[5,10,15,20,25,30] 1
Write the output of print(L1[::-2])
i. [30, 20, 10] ii. [5, 10, 15] iii.[30, 25, 20] iv.[30,20,5]
5. Which of the following commands can be used to read the next line in a file using the file object
<tmpfile>? 1
i. tmpfile.read(n) ii. tmpfile.read() iii. tmpfile.readline() iv.tmpfile.readlines()
6. Which of the following function is used to write multiple lines in a textfile? 1
i.writelines() ii.readlines() iii.write() iv.append()
7. What is the output of the following python statement? 1
print(10!=9 and 20>=20)
i.True ii.False iii.Error iv.No Output
8. If T=((1,2,3),(3,4)) , then what is T[0][1]? 1
i.2 ii. (1,2,3) iii.(3,4) iv. (1,2,3),(3,4)
9. What is the output of the following code ? 1
def fun(u, v, w=3):
return u * v * w
def bar(x):
y=4
return fun(x, y)
print(fun(4,5,6))
print(bar(10))

1
i. 120 ii.120 iii.60 iv.60
60 120 120 60
10. Which of the following mode is used to add new data to the end of old data in the file “story.txt”?
f =open("story.txt","__")
a. r b. a c. w 1
11. What is the output of the following python command:- 1
print(round(377.45))
i.377.4 ii.377.5 iii.377
12. Which SQL command is used to add a new column to an existing table in MySQL database? 1
i. ALTER ii.UPDATE iii.MODIFY
13. What characters are printed by the following statements? 1
s = "RPCSP2020"
for idx in range(len(s)):
if idx % 2 == 0:
print(s[idx],end=””)
a. RCP00 b. PS21 c.RPCSP2020
14. Which keyword is used to eliminate duplicate rows from the result of a SELECT statement? 1
i. DIFFERENT ii.DISTINCT iii.UNIQUE
15. Which among the following is the most appropriate list method to add multiple elements to
a list? 1
i.append() ii.extend() iii.insert()
16. How many times the word “welcome” is printed by the following python code snippet? 1
S="Python Language"
for I in S[-14:-2:2]:
print("welcome")
i.6 ii. 13 iii.7
Q17 and 18 are ASSERTION AND REASONING 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
17. Consider the following list:- 1
B=[1,2,3,4,5,6], the index of element 3 will be:
Assertion(A): the index of 3 will be either 2 or -4.
Reason(R):Python list supports forward and backward indexing: forward indexing starts with index
0 given to the leftmost element and backward indexing starts with index -1 given to the rightmost
element.
18. Asertion(A): Text files store information in ASCII or Unicode characters. 1
Reason(R ): In the text file , there is no delimiter for a line.
SECTION – B
19. Ankit has written a code to input a number and find its factorial. This code is showing errors, 2
Rewrite the corrected code and underline the correction made:-
Def fact():
N=input(“enter a number”)
F=1
For I in range[1,n+1];
2
F=F*I
print(“Factorial of “,N,’is’,F)
20. Distinguish between fetchall() and fetchmany() with suitable example. 2
OR
Explain role of execute() on the context of Python Interface with MySQL
21. a.Write output:- 1
x=”abcdef”
i=”I”
while i in x:
print(i,end=” ”)
b. What is the output of “hello”+1+2+3? 1
22. Distinguish between Primary Key and Unique Key. Give example to support your answer. 2
23. a. Write the full forms of the following:- 1
i.CSV ii.RDBMS
b. What is meant by scope of a variable? 1
24. Predict output of the python code given below:- 2
def f(m,n=50):
m=m+n
n=m-n
print(m,”@”,n)
return m
a=200
b=100
a=f(a,b)
print(a,”#”,b)
b=f(b)
print(a,”@”,b)
OR
def mnew(mystr):
newstr=" "
count=0
for i in mystr:
if count%2==0:
newstr=newstr+i.lower()
else:
if i.islower():
newstr=newstr+i.upper()
else:
newstr=newstr+i
count=count+1
newstr=newstr+mystr[:3]

3
print("The new string is",newstr)
mnew("Py@thon 2020")
25. Differentiate between DELETE and DROP commands in SQL with suitable example. 2
OR
Categorize the following SQL commands as DML and TCL:-
COMMIT,INSERT,SELECT,UPDATE

SECTION C
26. TABLE:PERSONAL
EMPNO NAME DOB CITY HOBBY
1 MANOJ 1980-08-30 PUNE MUSIC
2 VINOD 1999-02-23 DELHI GARDENING
3 ABHAI 2001-05-25 MUMBAI SPORTS
4 ALEX 1981-04-23 DELHI ART
5 RAMESH 1980-08-30 PUNE MUSIC

A) What will be the cardinality and degree of the above table after adding 3 more rows and 1 more
column? 1
B) Write the output of the queries (i) to (iv) based on the table Carden:- 2
CARDEN
CCod CarName Make Color Capacity Charge
e s
501 A-Star Suzuki Red 3 14
502 Indigo Tata Silver 3 12
503 Innova Toyota White 7 15
504 SX4 Suzuki Silver 7 14
505 CClass Mercedes Red 7 35
i. Select CarName from Carden where color like “%Red”;
ii. Select CarName, Make, Capacity from Carden order by Capacity desc;
iii. Select CarName from Cardern where color in (“Red”,”Silver”);
iv. Select CarName,Color from Carden where Capacity > 7 and Make like “T%”;
27. Assuming that a text file named first.txt contains some text written into it, write a function that 3
reads the file first.txt and creates a new file named second.txt, to contain only those words from
the file first.txt which start with a lowercase vowel (i.e. with 'a', 'e', 'i', 'o', 'u').
For example if the file first.txt contains
Carry umbrella and overcoat when it rains
Then the file second.txt shall contain
umbrella and overcoat it
OR
Write a function in Python to read lines from a text file diary.txt, and display only those lines, which
are starting with an alphabet 'P'.
If the contents of file is :
I hope you will please write to me from all the cities you visit.

4
Please accept them with the love and good wishes of your friend.
He never thought something so simple could please him so much.
The output should be:
Please accept them with the love and good wishes of your friend.
28. I)Write the SQL queries (i) to (iii) based on the relation EMPLOYEE 2+1

(a) Write query to display the details of EMPLOYEE in the descending order of their hire date
whose city is Paris or Mumbai.
(b) Write query to delete Sam’s record from the table EMPLOYEE.
II) Which command is used to see the structure of a table/relation?
29. Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers and n is a numeric value
by which all elements of the list are shifted to left.
Sample Input Data of the list Arr= [ 10,20,30,40,12,11], n=2 Output Arr = [30,40,12,11,10,20] 3
30. Write following function in Python to do transaction in a table STUDENT of database “ADIS” 3
Note : user id =”root” and password =”1234”
Desc Student

Rollno Number
Name Varchar(30)
Class Number
Section char(1)

Insert () – to accept student rollno, name , class and section for the user , then insert it as row into the
table STUDENT.
Search() – to search a student record based on name entered by the user.
SECTION D
31. Given a binary file emp.dat, containing records of following list format: 5
[empcode, name, and salary,location]
i. Write a python function that add one more record at the end of file.
ii. Write a python function that display all employee records whose location is “Delhi”
32. (a) What is the output of the following python code? 3
x=60
def f():
global x
print(“x=”,x)
x=10
print(“Now x=”,x)
f()
print(“value of x is “ ,x)
5
(b) Complete missing statements:- 2

OR
(a) Find the output of the following python code.
def fun():
M=[11,22,33,44]
Q=M
M[2]+=22
L=len(M)
for i in range(L):
print("Now@",Q[L-i-1],"#",M[i])
fun()

(b) Predict the output of the following python code:-

33. A csv file “Sports.csv” has structure: [code, item,category, cost, quantity] 5
i. Write a user defined function CreateFile() to input data for a record and add to Sports.csv
ii. Write a function CountRec(category) in Python which accept the category as parameter
and count and return number of items under that category stored in sports.csv.
OR

Create a csv file called “Contacts.csv” to store name and contact number of any 10 students .
Write a function to display its content.
SECTION E
34. IT department of an institution is planning to maintain its employees’ records using MySQL database.
As a database administrator Mr.Daniel has decided that: 2+2=4
Name of the Database – SoftTechDB
Name of the table – EMPLOYEE
The attributes of EMPLOYEE are as follows:
EmployeeID – Numeric
Ename – character of size 30

6
DeptID – Numeric of size 1
Salary -- numeric
Dname -- character of size 20
Dlocation --character of size 30

i. Identify the attribute best suitable to be declared as a primary key.


ii. Write the degree and cardinality of the table Employee.
iii. A)Insert the following data into the attribute EmployeeID, Ename, Salary and Dlocation
respectively in the given table EMPLOYEE.
EmployeeID=1008, Ename=”Sohal”, Salary=6000 and Dlocation=”Lucknow”
B) Increase salary of the employees by 5% whose name starts with letter A.
OR (only for option iii)
A) Delete all records from the table Employee.
B) Add a new column called “Commission” with float datatype.
35. Arun, during Practical Examination of Computer Science, has been assigned an incomplete search()
function to search in a pickled file student.dat. The File student.dat is created by his Teacher and the
following information is known about the file.
• File contains details of students in [roll_no,name,marks] format.
• File contains details of 10 students (i.e. from roll_no 1 to 10) and separate list of each student is
written in the binary file using dump().
Arun has been assigned the task to complete the code and print details of roll number 1.
def search():

f = open("student.dat",____) #Statement-1 1
try:
while True:
rec = pickle.____ #Statement-2 1
if ____: #Statement-3 1
print(rec)
except:
pass

____ #Statement-4 1

Fill in the blanks using appropriate statements/code

You might also like