Jeemangalam, Hosur.
Midterm Test (2023-’24)
Class: XII Marks: 35
Subject: Computer Science Duration: 1hr 30min
General Instructions:
1) This question paper contains five Sections-Section A to Section E.
2) All questions are compulsory.
3) Section A, consists of 10 questions. Each question carries 1 mark.
4) Section B, consists of 3 questions. Each question carries 2 marks.
5) Section C, consists of 2 questions. Each question carries 3 marks.
6) Section D, consists of 2 questions. Each question carries 4 marks.
7) Section E, consists of 1 question. This question carries 5 marks.
SECTION A
1. What type of objects can be used as keys in dictionaries? 1
Answer =
Immutable type of object can be used in dictionary.
Example = integer, string, tuple
2. Which of the following arguments works with implicit values that are
used if no value is provided? 1
(a) keyword
(b) required
(c) variable-length
(d) default
Ans:
d
3. A library can have multiple modules in it.(T/F) 1
Ans:
T
4. Add one column Email of data type VARCHAR and size 30 to the table
Customer. 1
Answer =
Alter table Customer add ( Email varchar(30) ) ;
5. This question is Assertion and Reason-based questions. 1
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
Assertion(A): Exception handling in Python allows for graceful
recovery from errors and prevents program crashes.
Reason(R): When an error occurs during program execution,
Python's exception handling mechanism allows the program to
gracefully handle the error and take corrective action.
Ans: C
6. Which line of code will cause an error? 1
1. num = [5, 4, 3, [2], 1]
2. print(num [0])
3. print(num[3][0])
4. print (num[5])
(a) Line 3
(b) Line 2
(c) Line 4
(d) Line 1
Ans:
(c )
7. What will be the output generated by the following snippet? 1
a = [5, 10, 15, 20, 25]
k=1
i = a[1] + 1
j = a[2] +1
m = a[k+1]
print (i, j, m)
(a) 11 15 16
(b) 11 16 15
(c) 11 15 15
(d) 16 11 15
Ans:
(b)
8. The error which is raised when we try to perform an operation on
incorrect type of value. 1
a.) IO Error
b.) Index Error
c.) Name error
d.) Type Error
Ans – d.) Type Error
9. Modify the definition of column Grade in Customer table. Increase its
size to 2. 1
Answer =
Alter table Empl modify column grade int(2) not null ;
10. What will be the output of the following Python code? 1
def foo():
try:
print(1)
finally:
print(2)
foo()
a)
b) a) 1 2
b) 1
c) 2
d) none of the mentioned
Answer: a
SECTION B
11. Predict the output of the following program: - 2
x = 'apple, pear, peach, grapefruit'
y = x. split(', ' )
for z in y :
if z < 'm' :
print(str.lower(z))
else :
print(str.upper(z))
Ans:
apple
PEAR
PEACH
grapefruit
>>>
12. Write a program that reads a string and checks whether it is a
palindrome string or not. 2
Answer =
string = input("Enter a string :")
length = len(string)
mid = int(length / 2)
rev = -1
for a in range (mid) :
if string[a] == string[rev] :
a += 1
rev -= 1
else :
print(string, "is not a palindrome")
break
else :
print(string, "is a palindrome")
13. What is the difference between the formal parameters and actual
parameters? What are their alternative names? Also, give a suitable
Python code to illustrate both. 2
Answer :-
Actual Parameter is a parameter, which is used in function call
statement to send the value from calling function to the called function.
It is also known as Argument.
Formal Parameter is a parameter, which is used in function header of
the called function to receive the value from actual parameter. It is also
known as Parameter.
SECTION C
14. Write a Python function that accepts a string and calculate the number
of uppercase letters and lowercase letters. 3
Ans:
def string_test(s):
d = {"UPPER_CASE" : 0, "LOWER_CASE" : 0}
for c in s:
if c.isupper():
d["UPPER_CASE"] += 1
elif c.islower ():
d["LOWER_CASE"] += 1
else:
pass
print ("Original String : ", s)
print ("No. of Uppercase characters : ", d["UPPER_CASE"])
print ("No. of Lowercase characters : ", d["LOWER_CASE"])
sentence = input ("Enter sentence :- ")
string_test(sentence)
15. Write SQL queries for (i) to (iii),which have the table name as Student. 3
(i) To display the records from table student in alphabetical order as
per the name of the student.
(ii) To display Class, Dob and City whose marks is between 450 and
551.
(iii) To display Name, Class and total number of students who have
secured more than 450 marks, class wise.
Answer =
(i)
SELECT * FROM Student ORDER BY Name;
(ii)
SELECT Class, DOB, City FROM Student
WHERE Marks BETWEEN 450 AND 551;
OR
SELECT Class, DOB, City FROM Student
WHERE Marks >= 450 AND Marks <= 551 ;
(iii)
SELECT Name, Class, COUNT(*) FROM Student
GROUP BY Class HAVING Marks > 450;
SECTION D
16. With reference to the table below, answer the questions that
follows: 4
Table: Employees
Empid Firstname Lastname Address City
010 Ravi Kumar Raj nagar GZB
105 Harry Waltor Gandhi nagar GZB
152 Sam Tones 33 Elm St. Paris
215 Sarah Ackerman 440 U.S. 110 Upton
24 Friends
244 Manila Sengupta street New Delhi
300 Robert Samuel 9 Fifth Cross Washington
335 Ritu Tondon Shastri Nagar GZB
121 Harrison
400 Rachel Lee St. New York
441 Peter Thompson 11 Red Road Paris
Table : EmpSalary
Empid Salary Benefits Designation
010 75000 15000 Manager
105 65000 15000 Manager
152 80000 25000 Director
215 75000 12500 Manager
244 50000 12000 Clerk
300 45000 10000 Clerk
335 40000 10000 Clerk
400 32000 7500 Salesman
Write the SQL commands for the following using above tables:
(i) To show firstname, lastname, address and city of all employees
living in Pairs.
(ii) To display the content of Employees table in descending order of
Firstname.
(iii) To display the firstname, lastname and total salary of all managers
from the tables Employes and Emp Salary, where total salary is
calculated as Salary + Benefits.
(iv) To display the maximum salary among managers and clerks from
the table EmpSalary.
Give the Output of following SQL commands:
(i) Select firstname, Salary from Employees, Empsalary where
Designation = 'Salesman' and Employees. Empid = Empsalary.Empid;
(ii) Select count(distinct designation) from EmpSalary:
(iii) Select designation, sum(salary) from EmpSalary group by
designation having count(*) > 2;
(iv) Select sum(Benefits) from EmpSalary where Designation = 'Clerk';
Answer =
(i)
Select firstname, lastname, address, city from Employee where city =
“Paris”;
(ii)
Select * from Employee order by Firstname desc;
(iii)
Select firstname, lastname , (Salary + Benefits) “total salary” from
Employee natural join EmpSalary ;
(iv)
Selec max(Salary) from EmpSalary where Designation in
(“Manager”, “Clerk”) ;
Output:
(i)
Fristname salary
Rachel 32000
Peter 28000
(ii)
count(distinct
designation)
4
(iii)
designation Sum(salary)
Manager 215000
Clerk 135000
(iv)
Sum(Benefits)
32000
17. Answer the given questions below:
a) Predict the outputs of the following programs: - 2
def AbyB(a , b):
try:
c = ((a+b) / (a-b))
except ZeroDivisionError:
print ("a/b result in 0")
else:
print (c)
# Driver program to test above function
AbyB(2.0, 3.0)
Output:
-5.0
a/b result in 0
c) What are the possible outcome(s) from the following code? Also,
specify the maximum and minimum values that can be assigned to
variable SEL. 2
import random
SEL=random. randint (1, 3)
ANIMAL = ["DEER", "Monkey", "COW", "Kangaroo"]
for A in ANIMAL:
for AA in range (0, SEL):
print (A, end ="")
print ()
(i) (ii) (iii) (iv)
DEERDEER DEER DEER DEER
MONKEYMONKEY DELHIMONKEY MONKEY MONKEYMONKEY
COWCOW DELHIMONKEYCOW COW
KANGAROOKANGAR
OOKANGAROO
KANGAROOKANGAROO KANGAROO
Ans. Maximum value of SEL is 3 and minimum is 1
(iv) is the correct option.
SECTION E
18. In a Database, there are two tables given below : 5
Write SQL Queries for the following :
(i) To display employee ids , names of employees, job ids with
corresponding job titles.
(ii) To display names of employees, sales and corresponding job titles
who have achieved sales more than 1300000.
(iii) To display names and corresponding job titles of those employees
who have ‘SINGH’ (anywhere) in their names.
(iv) Identify foreign key in the table EMPLOYEE.
(v) Write SQL command to change the JOBID to 104 of the EMPLOYEE
with ID as E4 in the table ‘EMPLOYEE’
Consider this table –
Answer =
(i) SELECT EMPLOYEEID , NAME , EMPLOYEE.JOBID , JOBTITLE FROM
EMPLOYEE NATURAL JOIN ON JOB ;
(ii) SELECT NAME , SALES , JOBTITLE FROM EMPLOYEE , JOB WHERE
EMPLOYEE.JOBID = JOB.JOBID AND SALES > 1300000 ;
(iii) SELECT NAME , JOBTITLE FROM EMPLOYEE , JOB WHERE
EMPLOYEE.JOBID = JOB.JOBID AND NAME LIKE “%SINGH%” ;
(iv) JOBID
(v) UPDATE EMPLOYEE SET JOBID = 104 WHERE EMPLOYEEID = "E4";