You are on page 1of 19

D.A.V.

SCHOOL
SREE NANDEESWARAR CAMPUS,
ADAMBAKKAM, CHENNAI-600088
Quaterly Examination-2023
Maximum Marks:70 Time Allowed: 3 hours

General Instructions:

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


2. All questions are compulsory.
3. Section A have 18 questions carrying 01 mark each.
4. Section B has 07 Very Short Answer type questions carrying 02 marks each.
5. Section C has 05 Short Answer type questions carrying 03 marks each.
6. Section D has 03 Long Answer type questions carrying 05 marks each.
7. Section E has 02 questions carrying 04 marks each.
8. All programming questions are to be answered using Python Language only.

Q.n Section-A Mark


o s
1 i) State True or False 1
“User defined functions requires import of the modules for its execution.”
Ans:False
ii) Which of the following symbols are used for comments in SQL?
(a) // (b) ‘’’….’’’ (c) /**/ (d) #

2 i) Which of the following is a valid datatype in Python? 1


(a)Set (b)none (c)Integral (d)Real

ii) Find the invalid identifier from the following


a) stud#marks b)Stud_age c)_studname_ d)Studno

3 i) Find the output. 1

pride="#G20 Presidency"
print(pride[-12:0:-1][::-1])
ans: G20
ii) What will the output?
>>> import math
>>> x=25
>>> y=5
>>>x/y+math.floor(6*2/3)
ans: 9.0

4 i) Consider the given expression: 1


1
not False and True or False and True or False and True

Which of the following will be correct output if the given expression is


evaluated?
(a) True b) False c) NONE d) Error

ii) Name the built-in mathematical function / method that is used to


return the smallest integer not less than N.
Ans: math.ceil()

5 i) Which of the following mode in file opening statement results or 1


generates an error if the file does not exist?

(a)a+ (b)r+ (c)w+ (d) None of the above

ii) What value does the following expression evaluate to?


>>> 2 + 9 * ((3 * 12) - 8) / 10
a. 27 b. 27.2 c. 27.8 d. None of these
6 i) Fill in the blank: 1

command is used to remove all the rows from the table student
inSQL.

(a)delete * from student (b)drop student


(c)delete student (d)delete from student

ii) Find the output


ls=[x-1 for x in range(10,1,-2)]
ls[ls[ls[ls[-2]]]]

ans:3

7 i)Which of the following is not a DDL command? 1


a) UPDATE b)ALTER TABLE c)CREATE TABLE d)DROP TABLE

ii) Identify the data type of INFO:


INFO = ['hello',str(203),int('A',16),tuple([5,6])]
a. Dictionary b. String c. Tuple d. List
8 1
i) Predict the output:
>>> birds=["parrot", "owl", "sparrow", "crow", "eagle", "vulture", "pigeon"]
>>> del birds[4]
>>> birds.remove("vulture")
>>> birds.pop(3)
>>> print(birds)
'crow'
['parrot', 'owl', 'sparrow', 'pigeon']
2
ii) Identify valid declaration of tuple
a)T={1,2,3,4,5} b) T=int(‘a’,16),int(“7”,8),0j
c)D=(12,-4,0,23,9) d) both b and c

9 i) Identify the data type of result of expression not 12 and 10 1


a)False b)int c)float d)bool

ii) Which is not a type of tokens from the following.


a) keyword b) literals c)Operators d)module

10 i) Given the list L=[-11,142,86,-51] ,write the output of 1

print(abs(int(str(L[-1:-2:-1]).strip('[ ]'))))
ans: 51

ii) Which of the following is/are mutable data type?


a)int b)string c)list d)dictionary
11 i) Which operator in SQL is used to compare a value to a specified list of 1
values
a)BETWEEN b)= c)IN d)ALL

ii) Which of the following is not an aggregate function?


a)AVG() b)SUM() c)UPPER() d)COUNT()
12 i) Which keyword is used to eliminate duplicate values in an SQL select 1
query?
a) unique b)distinct c)key d)all

ii)
count={}
count[(1,2,4)] = 5
count[(4,2,1)] = 7
count[(1,2)] = 6
count[(4,2,1)] = 2
tot = 0
for i in count:
tot=tot+count[i]
print(len(count)+tot)

a. 16 b. 17 c. 25 d. Tuples can’t be made keys of a dictionary

13 i) Which of the following outputs are not possible when we run the below 1
code?
import random
for a in range(3):

3
for b in range(3):
res=random.random()*4+12
res1=round(res,4)
print(res1,' ',end=' ')
print()

a) 12.1609 14.0326 15.0572


b) 12.6619 15.5386 11.8575
c) 14.8181 12.2747 14.1595
d) 11.1093 14.1352 12.5726

ii) Which point can be considered as difference between tuple and list?
a. Length b. Indexing c. Mutability d. Slicing

14 i) The return type of fetchall(),fetchmany(5),fetchone() methods are 1


_____, ______ & _______ respectively

a. tuples, List of tuples, tuple


b. tuples, 5 tuples, None
c. List of tuples, List of tuples, tuple
d. List of tuples, 5 tuples, tuple

ii) In string slicing, the start and stop can be given beyond limits. If it is then
a. raise exception IndexError
b. raise exception ValueError
c. return empty string
d. return the entire string
15 i) Ms. Hemanth is working on a string program with s=”computer”. He wants 1
to display last four characters of a string object named s. Which of the
following statement is true?
a. s[4:] b. s[:4] c. s[-4:] d. s[:-4]

ii) The statement del l[1:3] do which of the following task?


a. deletes elements 2 to 4 elements from the list
b. deletes 2nd and 3rd element from the list
c. deletes 1st and 3rd element from the list
d. deletes 1st, 2nd and 3rd element from the list
16 Select the correct output of the code: 1
i)
>>> 'T'.join(['1','2','3'])
a. 'T1T2T3T' b. 'T123T’ c. '1T2T3' d. error

ii)
>>> s='o o p s'
>>> ls=s.split()
>>> '-'.join(ls[0].upper()+ls[1].capitalize()+ls[2].swapcase()+ls[3].lower())

a) 'OOPs' b) '-O-O-P-s-' c) 'O-O-P-s'

4
d) Error because join takes one argument

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 1
i) Assertion ( A) : In SQL, the aggregate function Avg() calculates the
average value on a set of values and produce a single result.
Reason ( R) : The aggregate functions are used to perform some
fundamental arithmetic tasks such as Min(),Max(), Sum() etc

ii) Assertion - A function ends the moment it reaches a return


statement or all the statements in function body have been
executed.
Reason – Return statement ends a function execution even if it
is in the middle of the function.
Ans: b,a
18 i) Assertion(A):The resultset refers to a logical set of records that are 1
fetched from the database by executing an SQL query.
Reason(R):Resultset stored in a cursor object can be extracted by
using fetch(…) functions.

ii) Assertion- The open a file one should use the open() function,
open() is a built in function
Reason - The open () functions returns a file object, it is used to
read or modify the file accordingly.

Ans:a,b

SECTION B
19 Evaluate the following expressions: 2
a) 7*3+4**2//5-8
16
b) 7>5 and 8>20 or not 12>4
False
c) 2*(2*(len("01\n")))
12
d) 1 or None and 'a' or 'b'
1

20 i) PREDICT THE OUTPUT 2


t1=("Bangalore",[1,2,'3'],'S',(3,4,6),"Centre",10)
print(t1[-2:]+t1[3])

5
ans: ('Centre', 10, 3, 4, 6)
Given below the file hierarchy:
 LIBCOMSCI
__init__.py
Details.py

COMSCI

 __init__.py
 CSXI.py
 CSXII.PY

INFOPRAC
 __init__.py
 IPXI.py
 IPXII.py fun1()

i) Write the import statement to import CSXI


Import LIBCOMSCI.COMSCI.CSXI

ii) Write the statement to invoke fun1()


import LIBCOMSCI.INFOPRAC.IPXII as s
S. fun1()

iii) Write the name of the packages in the above description.


LIBCOMSCI, COMSCI, INFOPRAC

21 i) What is the rule followed by Python to resolve namespaces? Explain 2


with example
ii) What are aggregate and scalar functions in MYSQL? Give one example
for each.

22 Write the queries for the following questions using the table Product with 2
the following fields. (P_ Code, P_Name, Qty, Price)
(i) Display the price of product having code as P06.
Select price from product where P_code=’p06’;
(ii) Display the name of all products with quantity greater than 50 and price
less than 500
Select P_name from product where Qty>50 and price<500;
iii) Include the ‘discount’ column to the table with float values as data
Alter table product add discount float;
iv) Make P_Code as the primary key of the table.
Alter table product modify P_Code varchar(30)primary key;
(Or)
Alter table add Primary key(P_Code)
23 Given below the folder contents in the C:\ drive 2

C:\
6
FIRST
One.txt

SECOND
 Two.txt
 Three.txt

 THIRD
 Four.txt
 Five.txt

i) Write the absolute path to access ‘Five.txt’ file


ii) Write the relative path to access ‘Three.txt’ file if the PWD is ‘THIRD’
iii) Write the relative path to access ‘Four.txt’ file if the PWD is
‘SECOND’
iv) Write the absolute path to access ‘One.txt’ file

Note: PWD stands for present working directory

i)c:\second\third\five.txt
ii)..\three.txt
iii).\third\four.txt
iv)c:\one.txt

24 In the table Loan below 2


(a) Identify the candidate key(s) from the table Loan.
LoanID-candidate key
(b) Which field will be considered as the foreign key if the tables Customers
and Loan are related in a database?
ID-foreign key
c) Write the query and output of loan X customers.
Select* from Loan cross join customers;
d) Write degree and cardinality of the output obtained from question (c)
Degree-10,Cardinality-24

7
25 i) Rewrite the following code in Python after removing all syntax error(s).
Underline each correction done in the code.
def func(a=100,b):
if a<b:
print(a)
elif:
print(b)
return a+b
func()
answer

def func(b,a=100):
if a<b:
print(a)
elif:
print(b)
return a+b
func(20)

ii) Write output for the following code.


def encrypt(str):
str1=""
for i in str:
if i.isupper():
str1+=i.lower()
else:
str1+="*"
8
if i.islower():
str1+=i.upper()

return str1
s=encrypt("WeLcOmE")
print(s)

w*El*Co*Me

Section-C
26 i) Write a method Firstlast( ) in python to print the lines starting with ‘T’ 3
or ‘t’ or ending with ‘e’ or ‘g’ in a text file “ARTICLE.txt”
Example :

If the file contains the content given below:


This is a sample text file

Of a student

Named Rohit Malhotra


is created for the purpose of testing,

File Handling with text file.


Thank you.

Output:
This is a sample text file
is created for the purpose of testing,
File Handling with text file.
Thank you.

ii) Write a method RevText() to read a text file “input.txt” and print the
text in reverse order.
Example:
If the file content is as follows: I LOVE MY NATION
Output will be: NOITAN YM EVOL I

iii) Write a function ninetyperc() to display the records of students with


a total of 450 and above

The contents of the text file ‘marks.txt’ is as given below.


Vivek 460
Vimal Jain 440
Vidya Suresh 470
Viswa venkat 420

Output:

Vivek 460
9
Vidya Suresh 470

27 a) Write the outputs of the SQL queries (i) to (iv) based on the 3
relations Teacher and Placement given below:

Write the output for the following queries:


(i) SELECT Department, sum(Salary) FROM Teacher WHERE Salary>12000
GROUP BY Department;
Department Sum(salary)
Computer science 21000
History 90000
Mathematics 75000

ii) SELECT MAX(Date_of_Join),MIN(Date_of_Join) FROM Teacher WHERE


Gender=’M’;
Max(Date_of_Join) MIN(Date_of_Join)
2021-09-05 2019-01-10

iii) SELECT Name, Salary, T.Department, Place FROM Teacher T, Placement P


WHERE T.Department = P.Department AND T.Department Like ‘%o%’;
Name Salary Dept Place
Arun 12000 Computer Science Najpur
Saman 20000 History Ahmedabad
Samira 40000 History Ahmedabad
Shyam 30000 History Ahmedabad
shiv 21000 Computer Science Najpur

10
Write the SQL queries for the following statements:

iv) Write the command to remove all the tuples of teacher table
Delete from Teacher;

v) Write the command to modify the column Name to FACU_Name


Alter table teacher change Name FACU_Name varchar(30);

vi) Write the command to make T_ID as the primary key and P_ID as foreign
key of the respective tables
Alter table teacher modify T_ID int primary key;
Or

Alter table teacher add primary key(T_ID)

Alter table placement add foreign key(P_ID) references Teacher(TID);

28 i) Write a function countvow() to count the total number of lines starting with 3
vowel(Consider the merge.txt file)

ii) Write a method/function DISPLAYWORDS(FILENAME) in python to read


lines from a text file STORY.TXT, and display those words, which are having
maximum length.

iii) A text file contains alphanumeric text (say alphanum.txt).


Create a new file numeric.txt by writing only the numbers or digits
from the alphanum.txt into the numeric.txt

29 3
a. Write the outputs of the SQL queries (i) to (iii) based on the relations
Club and Coach given below:
Table : Club
Coach-id CoachName Age Sports DateOfApp Pay Sex
1 KUKREJA 35 KARATE 27/03/1996 1000 M
2 RAVINA 34 KARATE 20/01/1998 1200 F
3 KARAN 34 SQUASH 19/02/1999 2000 M
4 TARUN 33 BASKETBALL 01/01/1999 1500 M
5 ZUBIN 36 SWIMMING 12/01/1998 750 M
6 KETAKI 36 SWIMMING 24/02/1997 800 F
7 ANKITA 39 SQUASH 20/02/1998 2200 F
8 ZAREEN 37 KARATE 22/02/1997 1100 F
9 KUSH 41 SWIMMING 13/01/1997 900 M
10 SHAILYA 37 BASKETBALL 19/02/1998 1700 M

11
Table: Coach
Sports_Person Sex Coach-id
AJAY M 1
SEEMA F 2
VINOD M 1
TANEJA F 3
VINOTHINI F 8

Write the output of the following queries:


i. SELECT COACHNAME, PAY FROM CLUB WHERE PAY>1500 ORDER
BY DATEOFAPP ASC;
CoachName Pay
SHAILYA 1700
ANKITA 2200

ii. SELECT COACHNAME, AGE, PAY, 15/100*PAY+PAY BONUS FROM


CLUB WHERE DATEOFAPP < '01-JAN-1998';
CoachName Age Pay Bonus
KUKREJA 35 1000 1150
KETAKI 36 800 920
ZAREEN 37 1100 1265
KUSH 41 900 1035

iii. SELECT SUM(PAY) FROM CLUB WHERE DATEOFAPP > '31/01/1998';


Write the SQL queries for the following statements:
Sum(Pay)
7400

iv) Display the female coachname and their female Sports_Person


Select CoachName,Sports_person from club,Coach where
club.coach_id=coach.coach_id and club.sex=’f’ and coach.sex=’f’;

v) Display the count of Sports_Person allotted for each Coach


Select coachname,count(sports_person) from club,coach where
club. .coach_id=coach.coach_id group by club.coach_id;
vi) Display the avg pay sports wise
Select sports,avg(pay) from club group by Sports;

30 Write the following SQL queries. 3

12
a) Write a query to change the fare to 6000 of the flight whose FNO is
F104.
Update flight set fare=6000 where fno=’F104’;
b) Write a query to display the total number of MALE and FEMALE
PASSENGERS.
Select count(*),gender from passenger group by gender;

c) Write a query to display the NAME, corresponding FARE and F_DATE of


all PASSENGERS who have a flight to START from DELHI.
Select name,fare,f_date from passenger,flight where
passenger.fno=flight.fno and start=‘Delhi’;
d) Write a query to delete the records of flights which end at Mumbai.
Delete from flight where END=”Mumbai”;
e) Write a query to display the details of flight in the descending order of
flying date
Select * from flight order by f_date desc;

f) Write a query to display the info about the flight which has maximum
fare which starts from Mumbai
Select * from flight where fare=(select max(fare) from flight where
start=”Mumbai”) and start=”Mumbai”;
Section-D
31 a. Predict the output of the code given below 1+1 ½
+1 ½
def Display(str):
m=" "
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
13
else:
if i%2==0:
m=m+str[i-1]

else:
m=m+"#"
print(m)
Display('CBSE@Mrch23')

c
cb
cbs
cbse
cbseE
cbseEm
cbseEmR
cbseEmRC
cbseEmRCH
cbseEmRCH#
cbseEmRCH#2

b. Write the python code that


i) creates the following table Student
ii) insert 3 user input records in the database.
Table: Student
rno – integer
Name – string
cls – integer
Mks – integer
Note the following to establish connectivity between Python and MYSQL:
 Username is root
 Password is admin
 The table should exist in a MYSQL database named class12.
 The details (rno, name, cls and mks) are to be accepted from the user.

C. Write the python SQL connectivity code that


i) reads the following record from the table named Book and displays only
those records with the book price greater than 250 rs.:

BNo – integer BName – string BPrice – integer

ii) Change the Bprice as rs.500/- for the book “Wings of Fire”

Note the following to establish connectivity between Python and MYSQL:


• Username is root
• Password is DAV
• The table exists in a MYSQL database named Library.

32 a) Predict the output of the following program 1+1 ½


14
X = 100 +1 ½
def Change(P=10, Q=25):
global X
if P%6==0:
X+=100
elif Q%5==0:
X+=50
print(P,'#',Q,'$',X,'@')
a,b=18,50
Change()
Change(a,b)
Change(a)
Change(b)
Change(Q=13)

10 # 25 $ 150 @
18 # 50 $ 250 @
18 # 25 $ 350 @
50 # 25 $ 400 @
10 # 13 $ 400 @

b) Write a void function that receives a 4-digit no. and calculates the
sum of the squares of each digit in the number.
Example :
Enter a 4-digit no.1234
Sum of squares of digits=30

c) Write the function PRIMESEP(LS) to create the list of prime numbers


PRIMELS[] from the list of numbers.
Example:
LS=[67,66,89,87,43,24,23,12,11,13]
PRIMELS=[ [67, 89, 43, 23, 11, 13]

SECTION-E
33 a) Find output of the following code : 2+1
import sys ½ +1
s="""Wish ½
you
all
"""
f=open("abc.txt",'w+')
print(f.write(s))
f.flush()
f.seek(0)
15
print(f.read(3))
print(f.readline(4))
f.seek(4)
print(f.readlines(9))

13
Wis
h

['\n', 'you\n', 'all\n']

b) Write a function PERFECT_LIST(START, STOP), which finds the perfect


nos in the range START to STOP which is passed as argument to the
function. The function returns another list named ‘PERLIST’ that stores
the perfect nos. in the given range.
For example
START=1, STOP =1000:
PERLIST=[6,28,496,8128]

c) Write a python function HAPNUM(n) which takes an argument of


n(integer number) and check whether it is a “Happy Number” or not.

A number is said to be a “HAPPY NUMBER”, when the eventual sum of


the square of the digits of the number is equal to 1.
Example-1:
28=22+82=4+64=68
68=62+82=36+64=100
100=12+02+02=1+0+0=1
Thus 28 is a “HAPPY NUMBER”

Example-2:
21=22+12=4+1=5
Thus 21 is not a ‘HAPPY NUMBER”

34 Consider the table ‘PERSONS’ given below 5

16
Write the following SQL queries:

a) Display the SurNames, FirstNames and Cities of people residing in


Udhamwara city.
Select surname,firstname,city from persons where city=’udharwara’;
b) Display the Person Ids (PID), cities and Pincodes of persons in
descending order of Pincodes.
Select Pid,city,pincode from persons orderby pincode desc;
c) Display the First Names and cities of all the females getting Basic
salaries above 40000.
Select firstname,city from persons where gender=’f’ and
Basicsalary>40000;
d) Display First Names and Basic Salaries of all the persons whose
firstnames starts with “G”

Select firstname,BasicSalary from persons where firstname like’G%’;

Advaith,a manager has stored the details of departments in a table called


DEPARTMENT.
DEPTNO DNAME LOC
------------------------------------------------------------------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
50 SALES CALIFORNIA

He wants to add one more record to this table and has written the following
code and unable to insert that record.
INSERT INTO DEPARTMENT VALUES(43,”HRD”);

e) Help him to correct the code for adding the record


Insert into department(Deptno,Dname) values (43,HRD);
17
f) How can he restrict Null values in the table?
By giving NOT NULL constraint

Write a commands to :
g) show the names of department starting with “R”.
select Dname from department wher Dname like ‘R%’;
h) Change LOC as “New York” for DEPTNO 30.
Update department set LOC=’New York” where deptno=30;
i) delete the records of location(LOC) “Boston”
Delete from department where Loc=”Boston”;

j) Display the information about sales dept


Select * from department where Dname =’sales’;

35 Prashanth has created a database about students for a computer project 5


regarding performance analysis.

Table : STUDENT

RNo SNAME CLASS STREAM DOB TOT_MARKS GRADE


23 VIKRAM 12_A CS 2007/02/0 464 A3
1
45 KAMAL 12_B CS 2006/01/0 484 A1
2
22 FAHAD 12_C CS 2008/03/0 494 A1
3
12 ANTONY 12_D HUMAN 2007/04/0 467 A3
4
34 RAM 12_E BIO 2006/08/0 478 A2
7
11 RAMYA 12_F COM 2008/12/0 466 A3
9
9 VISHNU 12_A CS 2007/11/1 478 A2
0
36 VENDAN 12_A CS 2006/10/1 430 A4
2
26 NIRANJAN 12_A CS 2008/12/0 477 A2
2
16 SHYAM 12_D HUMAN 2007/02/3 474 A2
1
24 SUNDER 12_B CS 2006/01/3 489 A1
0
39 GOKUL 12_F COM 2008/02/2 489 A1
3
13 AKASH 12_F COM 2006/03/1 490 A1
4

Based on the above data given answer the following queries.


a) Display the name of the student getting maximum total in CS stream.
Select sname from student where TOT_MARKS desc;
b) Display the student table in the descending order of tot marks.
18
Select * from student orderby tot_marks desc;

c) Change the student ‘AKASH’ to BIO stream.


Update student set stream=’BIO’ where sname=’Akash’
d) Display the classes with students born in 2007.
Select distinct class from student where year(DOB)=2007;
e) Display the name, class, percentage of total for CS stream students
Selct sname,class,(TOT_MARKS*100)/500 as ‘percentage’ from student wher
stream=’CS’;
f) Change the grade A3 to B1 and A4 to B2 in a single query
Wrong Query
g) Display the name of the eldest student.
Select sname from student where DOB=(Select min(DOB) from Student);
h) Display the frequency of students stream wise.
Selct count(*),stream from student group by stream;
i) Display the names of students having the letter ‘A’ part of their name.
Select sname from student where sname like’%A%’;
j) Raise the marks of students by 3% for those who were born in the year
‘2008’
Update student set tot_marks=tot_marks+0.03*tot_marks where
year(DOB)=2008;

19

You might also like