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

COMPUTER SCIENCE-(A) \ 1 \ 8

Mid Term Examination


COMPUTER SCIENCE
MT-2022-12(A)

Time : 3 hrs. M. Marks : 70

General Instructions:
1. This question paper contains two parts A and B. Each part is com-
pulsory.
2. Both Part A and Part B have choices.
3. Part-A has 2 sections:
a. Section – I is short answer questions, to be answered in one
word or one line.
b. Section – II has two case studies questions. Each case study
has 4 case-based sub- parts. An examinee is to attempt any 4
out of the 5 subparts.
4. Part - B is Descriptive Paper.
5. Part- B has three sections
a. Section-I is short answer questions of 2 marks each in which
two question have internal options.
b. Section-II is long answer questions of 3 marks each in which
two questions have internal options.
c. Section-III is very long answer questions of 5 marks each in
which one question has internal option.
6. All programming questions are to be answered using Python
Language only

Section-I
Select the most appropriate option out of the options given for each question.
Attempt any 15 questions from question no 1 to 21.
1 Find the invalid expression(s) from the following. Justify
a. ob1 = 10,20,30,40
ob2 = ob1 *3
b. ob1 = {10:20,30:40}
ob2 = ob1 *3
c. ob1 = [10:20,30:40]
ob2 = ob1 *3
d. ob1 = “10:20,30:40”
ob2 = ob1 *3 (1)
COMPUTER SCIENCE-(A) \ 2 \ 8

2 Compare and comment on the following two return statements


return
return result (1)
3 Which method is used to write a list of strings to the file. Explain with example.(1)
4 How many times the following loop will execute? Justify your answer.
n = 10
while n <= 100:
print(n ** 2, end = “\t”) (1)
5 What will be the output of the following code.
def func(a, b=10, c=20):
print(a + b)
func(30, 70)
func(25, c = 30) (1)
6 Explain the use of global key word with example. (1)
7 What is top level segment in a Python program. Explain with example. (1)
8 What will be the output of the following code. Justify
def fun(str):
str =”abcd”
return str
str=”xyz”
fun(str)
print(str) (1)
9 Differentiate between extend() and insert() methods of list. (1)
10 What will be the output of the following code.
def change(n):
f, s= n // 10, n%10
while n != 0:
r = n%100
if r % 3 == 0:
f //= r
else:
s += 10
n //=100
return s, f
print(change(97531)) (1)
11 Explain tuple, Cardinlity (1)
COMPUTER SCIENCE-(A) \ 3 \ 8

12 Explain any one constraints which can be used to control Data Redundancy (1)
13 Give any two features of RDBMS software (1)

14 Identify the problem with the following SQL query


SELECT city, count(*) FROM sales WHERE count(*) > 5 GROUP BY city; (1)
15 What will be the output of the following code.
def tot(list1):
sum = 0
for k in list1:
if k % 10 > 2:
sum += k
else:
print(sum)
L1 = [22,31,45,53]
print(tot(L1)) (1)
16 Write statements to display the no. of characters present in a text file text.txt.
Assume that the file is opened in read mode. (1)
17 Differentiate between get() and values() method of dictionary (1)
18 Give one similarity and one difference between “r+” and “w+” mode (1)
19 Differentiate between read() and readline() method. (1)
20 Give any two features of a Text file. (1)
21 Explain Dynamic Typing with suitable example (1)
Section-II
Both the Case study-based questions are compulsory. Attempt any 4 sub parts
from each question. Each question carries 1 mark
22 A Gaming Club ‘Gamers’ is considering to maintain their data using SQL. As a
database administer, Abhay has decided that :
• Name of the database - Gamers
• Name of the table - COACH
• The attributes of STORE are as follows:
Coachid - numeric
No - numeric
CoachName – character of size 30
Salary – numeric
Sports - character of size 20
Rating – numeric
Grade – character of size 2
COMPUTER SCIENCE-(A) \ 4 \ 8

Region – character of size 20

Table- Coach
Coachid No Coachname Salary Sports Rating Grade Region
101 1 Aman 10000 Tennis 5 A Delhi
102 2 Karan 8500 Basketball 6 A Haryana
103 3 Rimsha 9000 Basketball 4 C Delhi
104 4 Akshit 8000 Cricket B Chandigarh
105 5 Antara 5000 Cricket 5 B Delhi
(a) Identify the attribute best suitable to be declared as a Candidate keys and
Alternate key, (1)
(b) Write the degree and cardinality of the table COACH (1)
(c) Insert a record in table COACH (Assume your own values) (1)
(d) Now Abhay wants to display the structure of the table COACH, i.e, name of
the attributes and their respective data types that he has used in the table.
Write the query to display the same. (1)
(e) Abhay want to remove the table COACH from the database Gamers. Which
command will he use from the following:
a) DELETE FROM Coach;
b) DROP TABLE Coach;
c) DROP DATABASE Gamers;
d) DELETE Coach FROM Gamers; (1)
23 Mr. X is writing a program to create a TEXT file “MyText.txt” which contains user
name and password for all students in a school. The username and passwords writ-
ten in the file are separated by a space. The user name is of fixed length i.e. 4
characters and passwords are of length 8. He has written the following code to
check for verification of password and username. As a programmer, help him to
successfully execute the given task.
Chk1, Str = 0, “ “
f = ______________________ #line1
nm = input(“Ënter user name”)
pwd = input(“Enter password”)
while True:
Str = f.readline()
wd = Str.split()
unm = ______________ #line2
pswd = _____________ #line3
____________________ #line4
COMPUTER SCIENCE-(A) \ 5 \ 8

print(“Password/ user name invalid”)


_________ #line5
(a) Give command to open the file in Line 1. (1)
(b) Line 2 should extract the user name (1)
(c) Line 3 should extract the password (1)
(d) Fill in the blank in Line 4 to check the validity of username and password(1)
(e) Give command to close the file in line 5 (1)
Part – B
Section-I
24 Evaluate the following expressions:
a) 2+5 // 9 * 5 + 3 ** 3 + 2 ** 3
b) not(7 > 5 and 5 > 12 ) or 15 > 2 and 15 < 2 (2)
25 a) Differentiate between natural join and cross join with example.
OR
b) Differentiate between having and where clause with example. (2)
26 Expand and explain the following terms. Give one command as example for each.
a. DDL b. DML (2)
27 a) Differentiate between modules and User Defined Function with suitable example.
OR
b) How the lifetime of an object is dependent on its scope. Justify by explaining the
lifetime of an object in two different scopes. (2)
28 Rewrite the following code in Python after removing all syntax error(s). Underline
each correction done in the code.
Cval, O1 = 30, 40
for i in range(65, 55)
if Cval % 2 != 0:
K+=2
elseif i % 2==0:
print (O1)
elseif o1==”40":
print(CVAL+10)
else:
print(“Cval” * 2) (2)
29 What possible outputs(s) are expected to be displayed on screen at the time of
execution of the program from the following code? Also specify the maximum values
that can be assigned to each of the object pos.
import random
COMPUTER SCIENCE-(A) \ 6 \ 8
List1 = [“Ravi”,”Jamuna”,”Chenab”,”Jhelum”]
for i in range(3,1,-1):
pos= random.randint(4-i,i)
print( List1[pos] , end=’$’)
(i) Jamuna$Jamuna$ (ii) Jhelum$Jamuna$
(iii) Jhelum$Chenab (iv) Jhelum$Ravi (2)
30 What do you understand by control structure? Explain control structure statements
used in Python with example. (2)
31 Differentiate between break and continue statements with suitable examples for each.
(2)
32 Differentiate between type promotion and typecasting with suitable example. (2)
33 Find and write the output of the following Python code: (2)

Section- II
34 Write a User defined function to take a dictionary D1 as argument. Where D1 has
Bookno as keyfield and a list containing bookname and price as value part. Transfer
all Book names to another list for those books whose price is more than 600. (3)
COMPUTER SCIENCE-(A) \ 7 \ 8

35 a) Write a function Count( ) in Python that counts the occurrences of lower case
vowels present in a text file “A1.TXT”.
If the contents of “A1.TXT” are as follows:
Class XII – Mid Term
Output - 3 (3)
OR
b) Write a function Count() in Python, which should should count and display the
occurrences of “The/ the/ THE” in a text file “Ä1.txt”
36 Write the outputs of the SQL queries (i) to (iii) based on the relations Teacher and
Posting given below: (3)

TABLE - Teacher
P_id T_ID Name Age Department Date_of_join Salary Gender
3 1 Jugal 34 Computer Sc 2017-01-10 12000 M
1 2 Sharmila 31 History 2008-03-24 20000 F
2 3 Sandeep 32 Mathematics 2016-12-12 30000 M
1 4 Sangeeta 35 History 2015-07-01 40000 F
2 5 Rakesh 42 Mathematics 2007-09-05 25000 M
1 6 Shyam 50 History 2008-06-27 30000 M
3 7 Shiv Om 44 Computer Sc 2017-02-25 21000 M
2 8 Shalakha 33 Mathematics 2018-07-31 20000 F

Table - Posting
P_id Department Place
1 History Agra
2 Mathematics Raipur
3 Computer Science Delhi

i. SELECT Department, count(*) FROM Teacher GROUP BY Department;


ii. SELECT Max(Date_of_Join), Min(Date_of_Join) FROM Teacher;
iii. SELECT Teacher.name,Teacher.Department, Posting.Place FROM Teacher,
Posting WHERE Teacher.p_id = Posting.p_id AND Posting.Place=”Delhi”;
37 a) Write a function Check(L1) in Python, where L1 is a list of numbers. From L1
create another list L2 such that L2 contains the number of digits in each element of
L1.
If L1= [12, 345, 5677] then L2= [2, 3, 4]
OR
COMPUTER SCIENCE-(A) \ 8 \ 8

b) Write a function Count(L1) in Python, where L1 is a list of numbers. Create


another list L2 from L1 such that L2 stores the sum of even digits of each element of
L1.
If L1= [12, 345, 5687] then L2= [2, 4, 14] (3)
Section-III
38 Consider a dictionary Employee- having empno as key, empname, sal and designa-
tion as values. Write User Defined Functions for the following-
- Check() which accepts employee dictionary as parameter and a string- D
containing designation. The function should count and return the total number
of employees with that designation with salary more than 30000.
- Check1() to accept employee dictionary as parameter and return the average
salary of all managers. (2½+2½)
39 Write SQL commands for the following queries (i) to (v) based on the relations
Student and Placement given below: (5)
Table - Student
P-id Rno Name Class DOB Gender City Marks
1 1 Anand XI 1997-06-06 M Agra 430
2 2 Chetan XII 1994-05-07 M Mumbai 460
1 3 Geet XI 1997-05-06 F Agra 470
2 4 Preeti XII 1995-08-08 F Mumbai 492
3 5 Saniyal XII 1995-10-08 M Delhi 360
3 6 Maahi XI 2009-12-12 F Delhi 256
2 7 Neha X 1995-12-08 F Mumbai 324
3 8 Nishant X 1995-06-12 M Delhi 429

Table : Placement
P_id Department Place
1 History Agra
2 Math Mumbai
3 Computer Science Delhi
i. To show all information about the students of History department who were
born in the month of September.
ii. To list the number of female students in each city.
iii. To list the details of all students whose name ends with “Ä”with their DOB in
descending order.
iv. To display class wise average marks .
v. To display students name and department for each student.
COMPUTER SCIENCE-(A) \ 9 \ 8

40 Attempt I or II
I)
Write a menu driven program to perform the following operations. Write User
Defined Functions for each option: (1+1+3)
(i) Create a file - A1.txt
(ii) Display the file contents
(iii) To read a text file “A1.txt” and count how many lines are ending with “ing”.

OR
II
b) a) Write a menu driven program to perform the following operations. Write
User Defined Functions for each option: (1+1+3)
(i) Create a file.
(ii) Display the file contents
(iii) To read a text file “A1.txt” and count how many words are ending with “ing”.

You might also like