Selfstudys Com File
Selfstudys Com File
a) [[2,3],[3,5],[4,1],[6,0.5]] b) [[2,3],[3,4],[5,6]]
c) [[0.5,1],[2,3],[3,4],[5,6]] d) [[6,0.5],[4,1],[2,3],[3,5]]
4. What are the possible outcome(s) executed from the following code? Also specify [1]
the maximum and minimum values that can be assigned to variable PICK.
import random
PICK= random.randint(0, 3)
CITY = ["DELHI", "MUMBAI", "CHENNAI", "KOLKATA"];
for I in CITY :
for J in range(l, PICK) :
print(I, end = " ")
print()
a) DELHI b) DELHIDELHI
MUMBAIMUMBAI MUMBAIMUMBAI
KOLKATAKOLKATAKOLKATA CHENNAICHENNAI
KOLKATAKOLKATA
c) DELHI d) DELHI
MUMBAI DELHIMUMBAI
CHENNAI DELHIMUMBAICHENNAI
KOLKATA
6. Computer communication signal which is in the form of the continuous wave is [1]
called
a) write() b) writelines()
c) writer() d) writerow()
8. Which of the following is correct to retrieve any character at index 'i' in string 's'? [1]
a) s.__getitem__(i) b) s.getitem(i-1)
c) s.__getitem__(i-1) d) s.getitem(i)
a) To filter out the row groups b) To filter out the column groups
c) To filter out the row values d) To filter out the row and
column values
a) Evaluation b) Create
c) Push d) Pop
13. Write a query to display the Sum, Average, Highest and Lowest salary of the [1]
employees grouped by department number.
a) Mesh b) Star
c) Tree d) Bus
a) list b) dictionary
c) tuple d) array
16. Which of the following join gives the intersection of two tables? [1]
17. Protective covering that protects the optical fiber from outside environment is [1]
known as
a) Core b) Jacket
c) Buffer d) Cladding
19. Assertion (A): In Python, a stack can be implemented using a list. [1]
Reasoning (R): A stack is an ordered linear list of elements that works on the
principle of First In First Out (FIFO).
a) Both A and R are true and R is b) Both A and R are true but R is
the correct explanation of A. not the correct explanation of
A.
20. Assertion (A): To store the data permanently into the file we use file handling. [1]
Reason (R): A file is a named location on a disk to store related information.
a) Both A and R are true and R is b) Both A and R are true but R is
the correct explanation of A. not the correct explanation of
A.
a) Both A and R are true and R is b) Both A and R are true but R is
the correct explanation of A. not the correct explanation of
A.
Section B
22. Give one advantage and one disadvantage of optical fiber cable and coaxial cable [2]
used in communication.
OR
If a is (1, 2, 3)
i. what is the difference (if any) between a * 3 and (a, a, a)?
ii. is a * 3 equivalent to a + a + a?
iii. what is the meaning of a[1:1]?
iv. what's the difference between a[1:2] and a[1:1]?
25. Consider the table Faculty whose columns name are [2]
F_ID, Fname, Lname, Hire_date, Salary, Course_name
Write the code to insert the following record into the above table.
101 Riya Sharma 12-10-2004 35000 Java Advance
102 Kiyaan Mishra 3-12-2010 28000 Data Structure
26. Write a program which will find all such numbers which are divisible by 7 but are [2]
not a multiple of 5, between 200 and 300 (both included).
OR
Underline the syntax errors in the following program
x = int(input("Enter first number:))
y = int(input("Enter second number:"))
z = int(input("Enter third number:")
a=x+b+z
print ("Result = ", b)
27. Write a Python program that read the data from file ‘original.dat' and delete the [2]
line(s) having word (passed as an argument). Then write these data after removing
lines into file 'duplicate.dat'.
OR
What is the output of following code?
fh = file ("poem.txt", "r")
size = len(fh.read( ))
print(fh.read(5))
Section C
29. Write definition of a method EvenSum(NUMBERS) to add those values in the list [3]
of NUMBERS, which are not odd.
OR
Find the errors in code given below:
i. def minus(total, decrement)
output = total - decrement
print(output)
return (output)
ii. define check()
N = input ('Enter N:')
i=3
answer = 1 + i * * 4/N
Return answer
iii. def alpha(n, string = 'xyz', k = 10) :
return beta(string)
return n
def beta (string)
return string == str(n)
print(alpha("Valentine's Day"):)
print(beta (string = 'true'))
print(alpha(n=5, "Good-bye") :)
OR
Consider the following Query :
SELECT brand, MAX(price)
FROM product
GROUP BY brand
HAVING price > 100 ;
The above query is giving error.
i. Identify and list the error.
ii. Correct the error so that only those brands get listed that have a max price more than
100.
iii. How will the corrected query's result be different from the following query?
SELECT brand, price
FROM product
WHERE price >100
GROUP BY brand;
31. Write the definition of a function ChangeGender() in Python, which reads the [3]
contents of a text file "BIOPIC.TXT" and displays the content of the file with
every occurrence of the word 'he' replaced by 'she'. For example, if the
content of the file "BIOPIC.TXT" is as follows:
Last time he went to Agra,
there was too much crowd, which he did not like.
So this time he decided to visit some hill station.
The function should read the file content and display the output as follows:
Last time she went to Agra,
there was too much crowd, which she did not like.
So this time she decided to visit some hill station.
OR
Define a function overlapping () that takes two lists and returns true if they have at least
one member in common, False otherwise.
Section D
32. Write a program to implement a stack for these book details (bookno, bookname). [4]
That is, now each item node of the stack contains two types of information -a
bookno and its name. Just implement push and display operations.
OR
Write a program to print a string in reverse order.
34. Give output for following SQL queries as per given table(s): [4]
Table: HOSPITAL
No. Name Age Department Dateofadm Charges Sex
1. Arpit 62 Surgery 21/01/98 300 M
2. Zarina 22 ENT 12/12/97 250 F
3. Kareem 32 Orthopedic 19/02/98 200 M
4. Arun 12 Surgery 11/01/98 300 M
5. Zubin 30 ENT 12/01/98 250 M
6. Ketaki 16 ENT 24/02/98 250 F
7. Ankita 29 Cardiology 20/2/98 800 F
8. Zareen 45 Gynecology 22/02/98 300 F
9. Kush 19 Cardiology 13/01/98 800 M
Nuclear
10. Shilpa 23 21/02/98 400 F
Medicine
i. SELECT COUNT (DISTINCT Charges) FROM HOSPITAL;
ii. SELECT MIN (Age) FROM HOSPITAL WHERE Sex = "F";
iii. SELECT SUM (Charges) FROM HOSPITAL WHERE Department = "ENT";
iv. SELECT AVG (Charges) FROM HOSPITAL WHERE Dateofadm< {12/08/98};
OR
Give output for following SQL queries as per given table(s) :
relation Teacher
No. Name Age Department Date of join Salary Sex
1. Jugal 34 Computer 10/01/97 12000 M
2. Sharmila 31 History 24/03/98 20000 F
3. Sandeep 32 Maths 12/12/96 30000 M
4. Sangeeta 35 History 01/07/99 40000 F
5. Rakesh 42 Maths 05/09/97 25000 M
6. Shyam 50 History 27/06/98 30000 M
7. Shiv Om 44 Computer 25/02/97 21000 M
8. Shalakha 33 Maths 31/07/97 20000 F
i. SELECT COUNT (distinct department) FROM TEACHER;
ii. SELECT MAX (Age) FROM TEACHER WHERE Sex = "F";
iii. SELECT AVG(Salary) FROM TEACHER WHERE Dateofjoin< {12/07/96};
iv. SELECT SUM (Salary) FROM TEACHER WHERE Dateofjoin < {12/07/96}
Section E
36. Ravya Industries has set up its new center at Kaka Nagar for its office and web [5]
based activities. The company compound has 4 buildings as shown in the diagram
below:
Center to center distances between various building is as follows:
Harsh Building to Raj Building 50 m
Raj Building to Fazz Building 60 m
Fazz Building to Jazz Building 25 m
Jazz Building to Harsh Building 170 m
Harsh Building to Fazz Building 125 m
Raj Building to Jazz Building 90 m
Number of Computers in each of the buildings is as follows:
Harsh Building 15
Raj Building 150
Fazz Building 15
Jazz Building 25
i. Suggest the most suitable place (i.e., building) to house the server of this
organisation with a suitable reason.
ii. Suggest the placement of the following devices with justification:
a. Internet Connecting Device/Modem
b. Switch
iii. The organisation is planning to link its sale counter situated in various parts of
the same city, which type of network out of LAN, MAN or WAN will be
formed? Justify your answer.
37. Write SQL queries for (i) to (vii) on the basis of table ITEMS and TRADERS: [5]
Table: ITEMS
ICODE INAME QTY PRICE COMPANY TCODE
1001 DIGITAL PAD 12i 120 11000 XENITA T01
1006 LED SCREEN 40 70 38000 SANTORA T02
1004 CAR GPS SYSTEM 50 21500 GEOKNOW T01
1003 DIGITAL CAMERA 12X 160 8000 DIGICLICK T02
1005 PEN DRIVE 32 GB 600 1200 STOREHOME T03
Table: TRADERS
TCode TName City
101 ELECTRONIC SALES MUMBAI
103 BUSY STORE CORP DELHI
102 DISP HOUSE INC CHENNAI
i. To display the details of all the items in ascending order of item names (i.e.,
INAME).
ii. To display item name and price of all those items, whose price is in the range of
10000 and 22000 (both values inclusive).
iii. To display the number of items, which are traded by each trader. The expected
output of this query should be:
T01 2 T02 2 T03 1
iv. To display the price, item name and quantity (i.e., qty) of those items which have
quantity more than 150.
v. To display the names of those traders, who are either from DELHI or from
MUMBAI.
vi. To display the names of the companies and the names of the items in descending
order of company names.
vii. Obtain the outputs of the following SQL queries based on the data given in
tables ITEMS and TRADERS above.
a. SELECT MAX (PRICE), MIN (PRICE) FROM ITEMS;
b. SELECT PRICE*QTY FROM ITEMS WHERE CODE=1004;
c. SELECT DISTINCT TCODE FROM ITEMS;
d. SELECT INAME, TNAME FROM ITEMS I, TRADERS T WHERE
I.TCODE=T.TCODE AND QTY<100;
OR
Consider the following tables CABHUB and CUSTOMER and answer (b) and (c) parts
of this question:
Table: CABHUB
Vcode VehicleName Make Colour Capacity Charges
100 Innova Toyota WHITE 7 15
102 SX4 Suzuki BLUE 4 14
104 C Class Mercedes RED 4 35
105 A-Star Suzuki WHITE 3 14
108 Indigo Tata SILVER 3 12
Table: CUSTOMER
Ccode Cname Vcode
1 Hemant Sahu 101
2 Raj Lai 108
3 Feroza Shah 105
4 Ketan Dhal 104
a. Give a suitable example of a table with sample data and illustrate Primary and
alternate Keys in it.
b. Write SQL commands for the following statements:
i. To display the names of all the white-colored vehicles.
ii. To display the name of vehicle name and the capacity of vehicles in ascending
order of their sitting capacity.
iii. To display the highest charges at which a vehicle can be hired from CABHUB.
iv. To display the customer name and the corresponding name of the vehicle hired by
them.
c. Give the output of the following SQL queries:
i. SELECT COUNT (DISTINCT Make) FROM CABHUB;
ii. SELECT MAX(Charges), MIN(Charges) FROM CABHUB;
iii. SELECT COUNT (*) Make FROM CABHUB;
iv. SELECT Vehicle FROM CABHUB WHERE Capacity=4;
Solution
SAMPLE QUESTION PAPER - 3
Computer Science (083)
Class XII (2024-25)
Section A
1. (a) True
Explanation:
The result of both of these expressions is same because the presence of parenthesis does
affect the order of precedence.
2. (a) Data Definition Language
Explanation:
Data Definition Language is a language used to define data structures and modify data.
3. (a) [[2,3],[3,5],[4,1],[6,0.5]]
Explanation:
Sorting is done by giving preference to first value of each list.
4.
(c) DELHI
MUMBAI
CHENNAI
KOLKATA
Explanation:
PICK can have maximum value 3 and minimum value 0.
5. a. si no
b. dict_values([['Rahul', 95], ['Siya', 90], ['Rajan', 80]])
6.
(d) analog signal
Explanation:
Analog Signal, a continuous time varying signal, which represents a time varying quantity.
7. (a) write()
Explanation:
write()
8. (a) s.__getitem__(i)
Explanation:
It is the correct syntax to call character at index i of string s
9. (a) To filter out the row groups
Explanation:
A HAVING clause is used to filter values from a group.
10. The code will open the file myfile.txt first by open function and then by seek() method
place the pointer 10 bytes before the end of file. Lastly, it will tell the position of the file
pointer from the starting of the file.
11. (a) True
Explanation:
True
12.
(c) Push
Explanation:
The process of inserting an element in a stack is called push operation.
13. mysql > SELECT SUM (sal), AVG (sal), MAX (sal), MIN (sal) FROM empl GROUP BY
deptno;
14. (a) Mesh
Explanation:
Mesh
15.
(c) tuple
Explanation:
The items of the tuple are separated with a comma (,) and enclosed in parentheses ()
16. (a) Inner join
Explanation:
Inner join
17.
(c) Buffer
Explanation:
Core is the part through which light travels.
Cladding covers the core and reflects light back to it.
Buffer is the fiber protection.
Jacket is not in the context.
18. (a) Option (i)
Explanation:
Operating someone’s Internet banking account, without his knowledge.
19.
(c) A is true but R is false.
Explanation:
A is true but R is false.
20.
(b) Both A and R are true but R is not the correct explanation of A.
Explanation:
The file handling plays an important role when the data needs to be stored permanently in
the file. A file is a named location on a disk to store related information.
21.
(b) Both A and R are true but R is not the correct explanation of A.
Explanation:
The python float() function converts the passed value into floating point number and
returns the floating point number.
Section B
22. Optical Fiber Cable:
Advantage: It is free of electrical noise and interference.
Disadvantage: It is an expensive communication medium.
Coaxial cable:
Advantage: It provides a cheap means of transporting multi-channel television signals
around metropolitan areas.
Disadvantage: When using coaxial cables over long distances, signal loss is a
disadvantage.
23. import mysql.connector
mycon = mysql.connector.connect(host = "localhost",user = "root",passwd = "system",data
cursor = mycon.cursor()
db = cursor.execute("CREATE TABLE Faculty(F_ID varchar(3) Primary key, Fname varch
mycon.close()
24. i. The above code will produce Error as we can iterate only on keys in a dictionary. Thus
the line:
for x, y in dnry:
is wrong and it will give error.
ii. dnry={0: 'a', 1: 'b', 2: 'c'}
for x in dnry:
print(x, dnry[x])
# output for this will be:
0a
1b
2c
OR
i. Expression a * 3 will give a tuple while (a, a, a) will give a nested tuple :
>>> a = (1, 2, 3)
>>> a * 3
(1, 2, 3, 1, 2, 3, 1, 2, 3)
>>> (a, a, a)
((1, 2, 3), (1, 2, 3), (1, 2, 3))
ii. Yes
iii. Empty tuple ( )
iv. a [1:2] will give a tuple with one item while a[1:1] will give an empty tuple.
25. import mysql.connector
mycon=mysql.connector.connect(host="localhost",user="root",passwd="system",database=
cursor=con.cursor()
sql="INSERT INTO Faculty (F_ID, Fname, Lname, Hire_date, Salary, Course_Name) VAL
val=[(101, 'Riya', 'Sharma', '12-10-2004', 35000, 'Java Advance'), (102, 'Kiyaan', 'Mishra', '
try:
cursor.executemany(sql, val)
mycon.commit()
except:
mycon.rollback()
mycon.close()
26. l = []
for i in range(200, 300):
if(i%7==0) and (i%5!=0)
l.append (str(i))
print(','.join(l))
OR
x = int(input("Enter first number : "))
y = int(input("Enter second number:"))
z = int(input("Enter third number:"))
a=x+y+z
print("Result = ", a)
27. import os
def Delete (word):
file1=open('original.dat', 'rb')
nfile=open('duplicate.dat', 'wb')
while True:
line=file1.readline()
if not line:
break
else:
if word in line:
pass
else:
print(line)
nfile.write(line)
file1.close()
nfile.close()
OR
No output
Explanation: The fh.read() of line 2 will read the entire file content and place the file
pointer at the end of file. For the fh.read(5), it will return nothing as there are no bytes to
be read from EOF thus print() statement prints nothing.
28. Dictionary can also be pass to the function by following example. e.g.
def dic(a):
for i in a:
print(i , ":", a [i])
dic({1:"One", 2:"Two", 3:"Three"})
Output
1 : One
2 : Two
3 : Three
Section C
29. def EvenSum (NUMBERS):
even_sum = 0
for num in range (len(NUMBERS)):
if NUMBERS[num] %2 == 0 :
even_sum = even_sum + NUMBERS[num]
print (even_sum)
OR
i. Syntax error. Colon ( : ) missing in the end of function header. Colon should be added
to end of function header.
ii. Syntax error. Keyword to define a function is def ( not define).
Also, colon ( : ) missing in the end of function header.
Return is not a valid statement. It should be return.
iii. No error in function alpha's definition.
Multiple return statements are syntactically legal. But in the above code, the second
return statement is unreachable. You can return multiple values by using return value1,
value2.
In function beta()'s definition, Colon (:) missing in the end of function header.
In __main__part, the colons at the end of first and third print( ) statements is invalid
(not enclosed in quotes)
In third print( ) statement, in the function call of alpha( ), positional argument follows
keyword argument, which is a syntax error.
30. i. Removing the Column "DISCOUNT": To remove the column named "DISCOUNT"
from the existing "ITEMS" table, we can use the following SQL command:
ALTER TABLE ITEMS DROP COLUMN DISCOUNT;
ii. Categorizing SQL Commands:
DDL (Data Definition Language):
CREATE: Used to create a new database or its objects.
DROP: Used to delete objects (e.g., tables) from the database.
DML (Data Manipulation Language):
INSERT: Used to add new records to a table.
UPDATE: Used to modify existing records in a table.
OR
i. The condition price > 100 with HAVING clause is error because with group by groups
of records get created that contain the summary result and price > 100 is applicable on
individual records and not on group of records.
ii. SELECT brand, MAX(price) FROM product GROUP BY brand HAVING MAX(price)
> 100 ;
iii. The corrected query will return only those groups where MAX(price) > 100.
But the given query will first extract records with price > 100 and then group them on
the basis of column brand.
31. def ChangeGender():
try:
# Read the content from the file
with open("BIOPIC.TXT", "r") as file:
content = file.read()
# Replace 'he' with 'she'
modified_content = content.replace("he", "she")
#Display File before modification:
print("Original content:\n", content)
# Display the modified content
print("Content After Modification:\n", modified_content)
except FileNotFoundError:
print("File 'BIOPIC.TXT' not found.")
# Call the function
ChangeGender()
OR
def overlapping (list1, list2):
len_1 = len(list1)
len_2 = len(list2)
for i in range (0, len_1):
for j in range (0, len_2):
if list1[i]==list2[j]:
return True
else:
return False
Section D
32. Implementation of stack for push and display operation:-
def isEmpty(stk):
if stk==[ ]:
return True
else:
return False
def pushbook(stk, item):
stk. append (item)
top=len(stk)-1
def displaybook(stk):
if isEmpty(stk):
print “Stack Empty”
else:
top = len(stk)-1
print “Book No----- Book Name”
for a in range (top, -1,-1)
print stk[a].split( )
#main
stack = [ ]
top = None
while True:
print “Books”
print “1. Add a book”
print “2. Display list”
print “3. Exit”
ch=int (row_input(“Enter your choice 1-3:”))
if ch == 1:
bno = row_input(“Enter Book No.”)
bname = row_input(“Enter Book Name”)
item = [bno, bname]
pushbook(item, stk)
row_input()
elif ch == 2:
displaybook(stk)
row_input()
elif ch==3:
break
else:
print “Invalid choice!”
row_input( )
OR
To print a string in Reverse order:-
def pushstack(stack, ch):
stack, append(ch)
top=len(stack)-1
return
def popstack (stack):
if isempty(stack):
return
else
top=len(stack)-1
for a in range(top, -1, -1)
print stack[a],
return
def isempty (stack):
if stack==[]:
else:
return True
else:
return False
#.....main.....
str=[]
top=None
str=raw_input(“Enter a string”)
while a in str:
pushstack(stk, str)
print “------ Reverse-------“
popstack(stk)
33. i. A.Output 1
God made the Earth; Man made confining countries
And their fancy-frozen boundaries.
But with unfound boundless love
I behold the borderland of my India
Expanding into the World.
Hail, mother of religions, lotus, scenic beauty and sages!
ii. B.Output 2
God made the Earth;
iii. C.Output 3
God made
iv. D.Output 4
God made
v. E. Output of Readlines function is
[ 'God made the Earth;\n', 'Man-made confining countries\n', 'And their fancy frozen
boundaries. \n', ' But with unfound boundless love\n', ' I behold the borderland of my
India\n', ' Expanding into the World. \n', 'Hail, mother of religions, lotus, scenic beauty,
and sages!']
34. i. COUNT (DISTINCT Charges)
5
ii. MIN (Age)
16
iii. SUM (Charges)
750
iv. AVG (Charges)
385
OR
OUTPUT
i. 3
ii. 35
iii. 0
iv. 0
35. import mysql.connector
my=mysql.connector.connect(host = "localhost",user="Root",passwd="System",database=
cursor=my.cursor()
db=cursor.execute("CREATE TABLE Watches (Watch_Id varchar(5) Primary Key, WatchN
sql = "INSERT INTO Watches(WatchId, WatchName, Price, Type, Qty_store) VALUES (%
val=[("W001", "High Time", 10000, "Unisex", 100),("W002", "Life Time", 15000, "Ladies
try:
cursor.executemany(sql, val)
my.commit();
except:
my.rollback()
my.close()
Section E
36. i. The most suitable place/block to house the server of this organisation would be Raj
Building, as this block contains the maximum number of computers, thus decreasing
the cabling cost for most of the computers as well as increasing the efficiency of the
maximum computers in the network.
ii. a. Raj Building
b. In the layouts, a hub/switch each would be needed in all the buildings, to
interconnect the group of cables from the different computers in each block.
iii. The type of network that shall be formed to link the sale counters situated in various
parts of the same city would be a MAN because MAN (Metropolitan Area Networks)
are the networks that link computer facilities within a city.
37. i. SELECT * FROM ITEMS ORDER BY INAME ASC;
ii. SELECT INAME, PRICE FROM ITEMS WHERE PRICE = > 10000 AND PRICE = <
22000;
iii. SELECT TCODE, COUNT (CODE) FROM ITEMS GROUP BY TCODE;
iv. SELECT PRICE, INAME, QTY FROM ITEMS WHERE QTY > 150;
v. SELECT TNAME FROM TRADERS WHERE (CITY = "DELHI") OR (CITY =
"MUMBAI")
vi. SELECT COMPANY, INAME FROM ITEMS ORDER BY COMPANY DESC;
vii. a. 38000
1200
b. 1075000
c. T03
d. LED SCREEN 40 DISP HOUSE INC CAR GPS SYSTEM ELECTRONICS sales
OR
a. Primary key of CABHUB table given in question = Vcode alternate key of CABHUB
table = Vehicle Name. The Primary key of Customer table = Ccode Alternate Key of
CUSTOMER = Cname.
b. i. SELECT VehicleName FROM CABHUB WHERE Colour = "WHITE";
ii. SELECT VehicleName, capacity From CABHUB ORDER BY Capacity ASC;
iii. SELECT MAX(Charges) FROM CABHUB;
iv. SELECT Cname, VehicleName FROM CABHUB, CUSTOMER WHERE
CUSTOMER. Vcode= CABHUB. Vcode;
c. i. 4