Selfstudys Com File
Selfstudys Com File
2. Which of the following function returns the total number of values? [1]
a) MIN b) MAX
c) COUNT d) SUM
4. s = ' ' (single space). Then s.isalnum( ) will return ________. [1]
a) False b) Error
c) True d) nothing
6. Which of the following is not the possible ways of data exchange? [1]
a) Multiplex b) Simplex
c) Half-duplex d) Full-duplex
7. Which of the following is mode of both writing and reading in binary format in [1]
file?
a) wb+ b) wb
c) w d) w+
8. fetchone() method fetches only one row in a ResultSet and returns a ________. [1]
a) String b) Tuple
c) Dictionary d) List
9. Which operator tests the column for the absence of data (i.e., NULL value)? [1]
10. Write a single loop to display all the contents of a text file poem.txt after removing [1]
leading and trailing whitespaces.
12. When a stack, implemented as an array/list of fixed size, is full and no new element [1]
can be accommodated, it is called an ________.
a) OVERFLOW b) NOFLOW
c) EXTRAFLOW d) UNDERFLOW
14. A ________ is a network spread across states, countries or whole world. [1]
a) PAN b) LAN
c) WAN d) MAN
15. Which two operators can be used on numeric values in Python? [1]
A. @
B. %
C. +
D. #
a) B, D b) B, C
c) A, C d) A, D
17. Which of the following is the fastest media of data transfer? [1]
18. Protocol that enables transfer of voice over internet to make phone calls? [1]
a) POP3 b) VOIP
c) PPP d) FTP
19. Assertion (A): We can declare multiple exceptions in except statement. [1]
Reason (R): The try block may contain the statements which throw different type
of exceptions.
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): In the case of rb mode, the file pointer exists at the beginning of the [1]
file.
Reason (R): In the case of rb+ mode, the file pointer exists at the end of the file.
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.
21. Assertion (A): The python abs() function is used to return the absolute value of a [1]
number.
Reason (R): The python all() function doesn't accept an iterable object.
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. How is Coaxial cable different from Optical Fibre? [2]
OR
Find the errors in the following code and write the correct code.
s = [11, 13, 15]
for n in len(s) :
tot = tot + s[n]
print(tot)
i. Underline the corrections.
ii. Write the reason! error next to it in the comment form.
25. Which record will get inserted in the table by the following code? [2]
import mysql. connector as sqltor
mycon = sqltor .connect(host = "localhost”, user = "learner”, passwd = "fast”,
database=”test")
cursor = mycon.cursor()
query = "INSERT INTO books (title, isbn) VALUES(%s, %s)".%
(fUshakaalJ, '12678987036')
cursor.execute(query)
mycon.commitO
26. Write a method in python to display the elements of list thrice if it is a number and [2]
display the element terminated with if it is not a number.
For example, if the content of list is as follows :
List =['41', 'DROND', 'GIRIRAJ', ’13', 'ZARA']
The output should be
414141
DROND#
GIRIRAD#
131313
ZARA#
OR
Write a program that reads an integer N from the keyboard computes and displays the
sum of the numbers from N to (2 * N) if N is nonnegative. If N is a negative number,
then it's the sum of the numbers from (2 * N) to N. The starting and ending points are
included in the sum.
27. Write a function in Python to count the number of lowercase and uppercase [2]
characters in a text file "Book.txt".
OR
Write a function Revstring () to read a textfile "Input.txt" and prints the words starting
with 'O' in reverse order. The rest of the content is displayed normally.
Example:
If content in the text file is:
UBUNTU IS AN OPEN SOURCE OPERATING SYSTEM
Output will be:
UBUNTU IS AN NEPO SOURCE GNITAREPO SYSTEM
(words 'OPEN' and 'OPERATING' are displayed in reverse order)
Section C
29. Write a function which takes two string arguments and returns the string [3]
comparison result of the two passed strings.
OR
Write the term suitable for following descriptions:
i. A name inside the parentheses of a function header that can receive value.
ii. An argument passed to a specific parameter using the parameter name.
iii. A value passed to a function parameter.
iv. A value assigned to a parameter name in the function header.
v. A value assigned to a parameter name in the function call.
vi. A name defined outside all function definitions.
vii. A variable created inside a function body.
30. Write separate user defined functions for the following: [3]
i. PUSH(N) - This function accepts a list of names, N as parameter. It then pushes
only those names in the stack named OnlyA which contain the letter 'A'.
ii. POPA(OnlyA) - This function pops each name from the stack OnlyA and
displays it. When the stack is empty, the message "EMPTY" is displayed.
For example:
If the names in the list N are
['ANKITA', 'NITISH', 'ANWAR', 'DIMPLE', 'HARKIRAT']
Then the stack OnlyA should store
['ANKITA', 'ANWAR', 'HARKIRAT']
And the output should be displayed as
HARKIRAT ANWAR ANKITA EMPTY
OR
Write the following user defined functions:
i. pushEven(N) - This function accepts a list of integers named N as parameter. It then
pushes only even numbers into the stack named EVEN.
ii. popEven(EVEN) - This function pops each integer from the stack EVEN and
displays the popped value. When the stack is empty, the message "Stack Empty" is
displayed.
For example:
If the list N contains
[10,5,3,8,15,4]
Then the stack, EVEN should store
[10,8,4]
And the output should be
4 8 10 Stack Empty
31. What do you understand by the local and global scope of variables? How can you [3]
access a global variable inside the function, if the function has a variable with the
same name?
OR
Write the definition of a function Sum3(L) in Python, which accepts a list L of integers
and displays the sum of all such integers from the list L which end with the digit 3.
For example, if the list L is passed
[123, 10, 13, 15, 23]
then the function should display the sum of 123, 13, 23, i.e. 159 as follows:
Sum of integers ending with digit 3 = 159
Section D
32. Write a program to implement a stack for these book details (book no., book name). [4]
That is, now each item node of the stack contains two types of information - a book
no. and its name. Just implement Push and display operations.
OR
Each node of a STACK contains the following information :
i. Pin code of a city,
ii. Name of the city.
Write a program to implement the following operations in the above stack
i. PUSH( ) To push a node into the stack.
ii. POP( ) To remove a node from the stack.
33. Consider the file p2.txt created above. Now predict the output of following code [4]
that works with p2.txt. Explain the reason behind this output.
fp1 = open("p2.txt", "r")
print(fp1.readline(20))
s1 = fp1.readline(30)
print(s1)
print(fpl.readline(25))
34. Consider the following tables CABHUB and CUSTOMER and answer the [4]
following parts of this question :
Table: CABHUB
Vcode VehicleName Make Color 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
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 VehicleName FROM CABHUB WHERE Capacity = 4;
OR
Consider the following tables PRODUCT and CLIENT. Write SQL commands for the
following statements.
Table: PRODUCT
P_ID ProductName Manufacturer Price
TP01 Talcum Powder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face Wash XYZ 95
Table: CLIENT
C_ID ClientName City P_ID
01 Cosmetic Shop Delhi FW05
06 Total Health Mumbai BS01
12 Live Life Delhi SH06
15 Pretty Woman Delhi FW12
16 Dreams Banglore TP01
i. To display the details of those Clients whose City is Delhi.
ii. To display the details of Products whose Price is in the range of 50 to 100 (Both
values included).
iii. To display the ClientName, City from table Client, and ProductName and Price from
table Product, with their corresponding matching P_ID.
iv. To increase the Price of all Products by 10.
Section E
36. Learn Together is an educational NGO. It is setting up its new campus at Jabalpur [5]
for its web-based activities. The campus has 4 compounds as shown in the diagram
below:
37. Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), [5]
which are based on the tables.
TRAINER
TID TNAME CITY HIREDATE SALARY
101 SUNAINA MUMBAI 1998-10-15 90000
102 ANAMIKA DELHI 1994-12-24 80000
103 DEEPTI CHANDIGARH 2001-12-21 82000
104 MEENAKSHI DELHI 2002-12-25 78000
105 RICHA MUMBAI 1996-01-12 95000
106 MANIPRABHA CHENNAI 2001-12-12 69000
COURSE
CID CNAME FEES STARTDATE TID
C201 AGDCA 12000 2018-07-02 101
C202 ADCA 15000 2018-07-15 103
C203 DCA 10000 2018-10-01 102
C204 DDTP 9000 2018-09-15 104
C205 DHN 20000 2018-08-01 101
C206 0 LEVEL 18000 2018-07-25 105
i. Display the Trainer Name, City & Salary in descending order of their Hiredate.
ii. To display the TNAME and CITY of Trainer who joined the Institute in the
month of December 2001.
iii. To displayTNAME, HIREDATE, CNAME, STARTDATE from tables
TRAINER and COURSE of all those courses whose FEES is less than or equal
to 10000. (iv) To display number of Trainers from each Ans. city.
iv. SELECT TID. TNAME, FROM TRAINER WHERE CITY NOT IN ('DELHT',
'MUMBAI');
v. SELECT DISTINCT TID EROM COURSE;
vi. SELECT TID, COUNT(*), MIN (FEES) FROM COURSE. CROUP BY TID
HAVING COUNT(*)>1;
vii. SELECT COUNTS), SUM(FEES) FROM COURSE WHERE STARTDATE<
'2018-09- 15';
OR
Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), Which
are based on the table.
Table: CUSTOMER
CNO CNAME ADDRESS
101 Richa Jain Delhi
102 Surbhi Sinha Chennai
103 Lisa Thomas Bangalore
104 Imran Ali Delhi
105 Roshan Singh Chennai
Table: TRANSACTION
TRNO CNO AMOUNT TYPE DOT
T001 101 1500 Credit 2017-11-23
T002 103 2000 Debit 2017-05-12
T003 102 3000 Credit 2017-06-10
T004 103 12000 Credit 2017-09-12
T005 101 1000 Debit 2017-09-05
i. To display details of all transactions of TYPE Credit from Table TRANSACTION.
ii. To display the CNO and AMOUNT of all Transactions done in the month of
September 2017 from table TRANSACTION.
iii. To display the last dale of transaction (DOT) front the table TRANSACTION for the
customer having CNO as 103.
iv. To display all CNO CNAME and DOT (date of transaction) of those CUSTOMERS
fron, tables CUSTOMER and TRANSACTION who have done transactions more
than or equal to 2000.
v. SELECT COUNT(*), AVG (AMOUNT) FROM TRANSACTION WHERE DOT >
= '2017-06-01'
vi. SELECT CNO, COUNT(*), MAX (AMOUNT) FROM TRANSACTION GROUP
BY CNO HAVING COUNT (*)> 1
vii. SELECT CNO, CNAME FROM CUSTOMER WHERE ADDRESS NOT IN
('DELHI', BANGALORE )
viii. SELECT DISTINCT CNO FROM TRANSACTION
Solution
SAMPLE QUESTION PAPER - 2
Computer Science (083)
Class XII (2024-25)
Section A
1. (a) True
Explanation:
True
2.
(c) COUNT
Explanation:
COUNT
3.
(d) All of these
Explanation:
It provides all the mentoined features.
4. (a) False
Explanation:
False
5. The output produced by given code will be:
False , a[1:1] , a[1:2] value is different
True a[1:1] , a[1:2] is same type
6. (a) Multiplex
Explanation:
Multiplex ,The process of combining the data streams is known as multiplexing
7. (a) wb+
Explanation:
wb+ mode opens a file for both writing and reading in binary format. It overwrites the file
if the file exists. If the file does not exist, creates a new file for reading and writing.
8.
(b) Tuple
Explanation:
Tuple
9. (a) IS NULL operator
Explanation:
The IS NULL operator is used in the database for representing that a particular field is
empty.
10. for line in file("poem.txt"):
print(line.strip())
11. (a) True
Explanation:
True
12. (a) OVERFLOW
Explanation:
When a stack, implemented as an array/list of fixed size, is full and no new element can be
accommodated, it is called an OVERFLOW.
13. DDL consists of various commands such as:
i. Create
ii. Alter
14.
(c) WAN
Explanation:
WAN spans a large geographical area, often a country or a continent and uses various
commercial and private communication lines to connect computers.
15.
(b) B, C
Explanation:
B, C
16. (a) group functions
Explanation:
group functions
17. (a) Fibre Optic
Explanation:
Fibre Optic
18.
(b) VOIP
Explanation:
VOIP stands for voice over internet protocol. It enables the transfer of voice using packet
switched network rather than using public switched telephone network. By using VOIP
software, phone calls can be done using standard internet connection.
19. (a) Both A and R are true and R is the correct explanation of A.
Explanation:
We can declare multiple exceptions in except statement since the try block may contain
statements which throw different type of exceptions. We can also specify an else block
along with the try-except statement, which will be executed if no exception is raised in the
try block and Finally block, which always gets executed either exception is generated or
not.
20.
(c) A is true but R is false.
Explanation:
In the case of rb mode, the file pointer exists at the beginning of the file. In the case of rb+
mode, the file pointer also exists at the beginning of the file.
21.
(c) A is true but R is false.
Explanation:
The abs() function is used to return the absolute value of a number. It takes only one
argument.
The all() function accepts an iterable object (such as list, dictionary, etc.). It returns true if
all items in iterable are true. Otherwise, it returns False.
Section B
22. Coaxial Cables is the most commonly used transmission media for LANs. It consists of
solid wire cores surrounded by one or more foil or wire shields, each separated by some
kind of plastic insulator whereas optical fibres consist of thin strands of glass or glass-like
materials.
Coaxial cables transmit electrical signals whereas Optical fibres transmit light signals or
laser signals.
23. import mysql.connector as mydb
con = mydb.connect (host = "localhost",user = "Admin",passwd = "Admin@123",database
cursor = con.cursor()
sql = "UPDATE Student SET Grade = 'A' WHERE Points > 8"
try:
cursor.execute (sql)
con.commit ()
except:
con.rollback ()
con.close ()
24. A data type, in programming, is a classification that specifies which type of value a
variable has and what type of mathematical, relational or logical operations can be applied
to it without causing an error.
Python's built-in core data types are:
i. Numbers (integer, floating-point, complex numbers, Booleans)
ii. String
iii. List
iv. Tuple
v. Dictionary
OR
s = [11, 13, 15]
tot = 0 # tot must be defined before being used
for n in range(len(s)) : # len(s) returns integer which is not iterable,
# to make an iterable from integer range() is used
tot = tot + s[n] # incorrect indentation
print(tot)
25. fUshakaalJ, 12678987036
26. List =['41', 'DROND', 'GIRIRAJ', '13', 'ZARA']
for w in List:
if w.isdigit(): # for numeric digits
print(w*3)
else:
print (w+"#") #for string
OR
N = int(input("Enter N: "))
step = N // abs(N)
sum = 0
for i in range(N, 2*N + step, step):
sum += i
print(sum)
27. def count_lower_upper():
name = “Book.txt”
lower = upper = 0
with open(name, 'r') as fileObject:
for line in fileObject:
for word in line:
for char in word:
if char.islower():
lower = lower + 1
if char.isupper():
upper = upper + 1
print("Number of lower case letters in file are ", lower)
print ("Number of upper case letters in file are", upper)
OR
def RevString():
fin=open('Input.txt')
S=fin.read()
for w in S.split():
if w[0]=='O':
print(w[::-1],end=' ') #ignore end
else:
print(w,end=' ') #ignore end
fin.close()
28. raw_input is a function which takes a string (e.g., a question) as argument, displays the
string to the terminal window, halts the program and lets the user write the input in the
terminal, and then the input is returned to the calling code as a string object.
e.g : name = raw_input("Enter your name : ") lets the user enter a string and returns the
value passed by the user to the variable name.
Section C
29. def stringCompare(str1, str2):
if str1.length() != str2.length() :
return False
else:
for i in range (str1.length()):
if str1[i] != str2[i]:
return False
else:
return True
b. def POPA(OnlyA):
result = []
while not OnlyA.is_empty():
result.append(OnlyA.pop())
return result
OR
a. def pushEven(N):
EVEN = Stack()
for num in N:
if num % 2 == 0:
EVEN.push(num)
return EVEN
b. def popEven(EVEN):
result = []
while not EVEN.is_empty():
popped_num = EVEN.pop()
result.append(popped_num)
print(popped_num, end=" ")
print("Stack Empty")
31. A global variable is a variable that is accessible globally. A local variable is one that is
only accessible to the current scope, such as temporary variables used in a single function
definition.
A variable declared outside of all the functions or in global scope is known as a global
variable. A global variable can be accessed inside or outside of the function whereas local
variables can be used only inside of the function. If a function has a local variable name as
a global variable, then in that function scope, the local variable will hide the global
variable with the same name. We can access a global variable having the same name as a
local variable by declaring its name with the keyword global, e.g., as global A. Global
variables are declared outside any function, and they can be accessed (used) on any
function in the program. Local variables are declared inside a function and can be used
only inside that function. It is possible to have local variables with the same name in
different functions.
OR
def Sum3(L):
total_sum = 0
last3 = []
for num in L:
if num % 10 == 3: # Check if the last digit is 3
last3.append(num) # Append qualifying numbers to last3 list
total_sum += num
print("Original List", L) # Display the original list
print("Numbers ending with digit 3:", last3) # Print the list
print(f"Sum of numbers ending with digit 3 = {total_sum}")
# Example usage
L = [123, 10, 13, 15, 23]
Sum3(L)
Section D
32. " " "
Stack: implemented as a list
top: integer having a position of a topmost element in Stack
"""
def cls( ):
print("\n"* 100)
def is Empty(stk) :
if stk== [ ] :
return True
else :
return False
def Push(stk, item) :
stk.append(item)
top = len(stk) - 1
def Display(stk) :
if isEmpty(stk) :
print ("Stack empty”)
else :
top = len(stk) - 1
print(stk[top], "<-top")
for a in range(top-1, -1, -1 ) :
print(stk[a])
# __main__
Stack = [] # initially stack is empty
top = None
while True :
cls()
print ("STACK OPERATIONS")
print("1. Push operation")
print("2. Display stack")
print("3. Exit")
ch = int(input("Enter your choice (1-5) :"))
if ch == 1 :
bno = int(input("Enter Book no. to be inserted :"))
bname = input ("Enter Book name to be inserted :")
item = [bno, bname] # creating a list from the input items.
PushfStack, item)
input()
elif ch == 2 :
Display(Stack)
input( )
elif ch == 3 :
break
else :
print("Invalid choice!")
input()
OR
MAX_SIZE = 1000
stack = [0 for i in range(MAX_SIZE)]
top = 0
def isEmpty():
global top
return top == 0
def push(x):
global stack, top
if top >= MAX_SIZE:
return
stack[top] = x
top += 1
def pop():
global stack, top
if isEmpty():
return
else:
top -= 1
return stack[top]
string = input().split()
for i in string:
push(i)
while not isEmpty():
x = pop()
print(x+x, end = ' ')
33. The output produced by above code will be:
A poem by Paramhansa
Yogananda
Better than Heaven or Arc
The reason behind this output is that the first file-read line (i.e., fp1.readline(20), read 20
bytes from the file pointer. As just after opening the file, the file pointer is at the beginning
of the file, the 20 bytes are read from the beginning of the file which returned string as "A
poem by Paramhansa \n" - this is because readlinei) returns the read string by adding an
end-line character to it (\n). So the first line of output was printed as:
A poem by Paramhansa
After the first readline(), the file pointer was at the space following word 'Paramhansa', so
the next readline() started reading from there and read 15 characters or end-of-the-line,
whichever is earlier. So the read string was "Yogananda\n" - notice the space before word
Yogananda. Hence came the second line of the output.
Now the file-pointer was at the beginning of the third line and the next readline (i.e.,
fp1.readline(25)) read 25 characters from this line and gave the last line of output.
34. i. 4
ii. 35 12
iii. Invalid query
iv. SX4
C Class
OR
i. SELECT * FROM CLIENT
WHERE City = ' Delhi ' ;
ii. SELECT * FROM PRODUCT
WHERE Price BETWEEN 50 AND 100 ;
iii. SELECT ClientName, City, ProductName, Price
FROM CLIENT, PRODUCT
WHERE CLIENT.P_ID = PRODUCT.P_ID ;
iv. UPDATE PRODUCT
SET Price = Price + 10 ;
35. import MySQLdb
db=MySQLdb.connect("localhost", "Adminxyz", " Axydm12", "xyzcorp")
cursor=db.cursor()
cursor.execute("DROP TABLE IF EXISTS CUSTOMER")
sql="Create Table Customer (CUSTNUMB CHAR(3) NOTNULL, CUSTNAME
CHAR(60) NOT NULL, ADDRESS CHAR(100), BALANCE Float, CREDLIM Float,
SLSRNUMB CHAR(2) NOT NULL)"
cursor.execute(sql)
cursor.close()
rec_ins=[('124', 'TINA ADAMS', '481 Tilak lane, CP, Delhi', 41800.75,50000, '3') ,('256',
'R VENKAT', '215 Mylapore, Chennai', 10,000.75 , 80000,’6'),('567', 'BHUVNA
BALAJI', '808 Bala Nagar, Hydarabad', 57000.75,50000,’6'),('622', 'PRATHAM JAIN',
'149 Plot 182, sec-9, Dwerka,Delhi', 57500.75,80000, '12')].
sql_insert= "INSERT INTO Customer (CUSTNUMB, CUSTNAME, ADDRESS,
BALANCE, CREDLIM,SLSRNUMB, VALUES ('%s', '%s', '%s', ' % f ' , '% f', %s,)"
cursor= db.cursror (prepared= TRUE)
try:
cursor. executemany (sql_insert, rec_ins)
print(cursor.rowcount, "All Records inserted")
db. commit()
except:
db.rollback()
cursor.close()
db.close()
Section E
36. i. The most suitable place to house the server is Training Compound as it has a maximum
number of computers.
ii. a. Repeater: As per one layout, the repeater can be avoided as all distances between the
compounds are <= 100 m.
b. Hub/Switch: Training compound as it is hosting the server.
iii. Optical Fibre
37. i. SELECT TNAME, CITY, SALARY FROM TRAINER ORDER BY HIREDATE
ii. SELECT TNAME, CITY FROM TRAINER WHERE HIREDATE BETWEEN '2001-
12-01' AND '2001-12-31'
SELECT TNAME, CITY FROM TRAINER WHERE HIREDATE > = '2001-12-01'
AND HIREDATE < = '2001-12-31';
iii. SELECT TNAME, HIREDATE, CNAME, STARTDATE FROM TRAINER.COURSE
WHERE TRAINER.TID= COURSE.TID AND FEES < = 10000;
iv. SELECT CITY, COUNT(*)) FROM TRAINER GROUP BY CITY;
v. TIDTNAME
103 DEEPTI
106 MANIPRABHA
vi. DISTINCT TID
101
103
102
104
105
v. 3 4833.33
vi. 2 12000