0% found this document useful (0 votes)
733 views9 pages

XII MS Computer Science PB-1 (2023-24)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 9

Pre Board 1 (2023-24)

CLASS-XII
SUBJECT: COMPUTER SCIENCE (083)
TIME: 3:00 Hours M.M.: 70
General Instructions:
1. This question paper contains five sections, Section A to E.
2. All questions are compulsory.
3. Section A has 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. One internal choice is given in
Q35 against part c only.
8. All programming questions are to be answered using Python Language only.

SECTION A 1*18=18
1. Which of the following is not a valid identifier name in Python? 1
a) 5Total b) _Radius c) pie d) While
2. Which is valid keyword? 1
a) Int b) WHILE c) While d) if
3 Which Constraint not allow to enter repeated values in the table? 1
a) PRIMARY KEY b) UNIQUE c) BOTH A and B d) None of above
4. Consider the following expression: 1
51+4-3**3//19-3
Which of the following will be the correct output if the expression is evaluated?
a) 50 b) 51 c) 52 d) 53
5. Select the correct output of the code: 1
Str=“Computer Science”
Str=Str[-4:]
print(Str*2)
a) ence b) enceence c) ecneecne d) None of these
6. Which module is imported for working with CSV files in Python? 1
a) csv b) python-csv connector c) CSV d) python.csvconnector
7. Fill in the blank: _____ command is used to update records in the MySQL table. 1
a) ALTER b) UPDATE c) MODIFY d) SELECT
8. Which command used to fetch rows from the table in database? 1
a) BRING b) FETCH c) GET d) SELECT
9. Which of the following statement(s) would give an error after executing the following 1
code?
print(9/2) # Statement-1
print(9//2) # Statement-2
print(9%%2) # Statement-3
print(9%2) # Statement-4
a) Statement-1 b) Statement-2 c) Statement-3 d) Statement-4
10. Fill in the blanks: 1
_______ is the table constraint used to stop null values to be entered in the field.
a) Unique b) Not NULL c) Not Empty d) None
11 The correct syntax of read() function from text files is: 1
a) file_object.read() b) file_object(read)
c) read(file_object) d) file_object().read
12 In SQL, we use _____ command to display the list of databases in the server. 1
a) SELECT DATABASES; b) SELECT DATABASE;
c) SHOW DATABASES; d) DESC;
13 Fill in the blank: ________ protocol is used to send mail. 1
a) SMTP b) FTP c) POP d) HTTPS
14 In a stack, if a user tries to remove an element from empty stack it is called _____. 1
a) Underflow b) Empty c) Overflow d) Blank
15 Which method is used for object serialization in Python? 1
a) Pickling b) Un-pickling c) Merging d) None of the above
16 To establish a connection with MySQL from Python which of the following functions is 1
used?
a) connection() b) connect() c) open() d) cursor()
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. Assertion (A):- In stack, program should check for Underflow condition, before 1
executing the pop operation.
Reasoning (R):- In stack, underflow mean there is no element available in the stack or
stack is an empty stack. Ans: A
18. Assertion (A):- The readlines() method in python reads all lines from a text file. 1
Reasoning (R):- The readlines() method returns the tuple of lines(string). Ans: C
Section B 2*7=14
19. Rajat has written the following Python code. There are some errors in it. Re-write the 2
correct code and underline the corrections made.
DEF execmain():
x = input("Enter a number:")
if (abs(x)=x):
print ("You entered a positive number")
else:
x=*-1
print "Number made positive:"x
execmain()
20. What is difference between message switching and packet switching? 2
OR
What is difference between delete and drop command in sql.
21. a. Find output generated by the following code: 2
mystr = “Hello I am a Human.”
print(mystr[::-3]) Ans: .m mIlH

b. Write the output of the code given below:


p=10
q=20
p*=q//3
p=q**2
q+=p Ans: 400 420
print(p,q)
22. Differentiate between fetchone() and fetchall() function. 2
23. a. Give the full form of the following: 2
i. URL
ii. SFTP
b. What is the use of Telnet?
24. Predict the output of the following code: 2
def CALLME(n1=1,n2=2):
n1=n1*n2
n2+=2
print(n1,n2)
CALLME() Ans: 2 4
CALLME(3) 64
OR
mylist = [2,14,54,22,17]
tup = tuple(mylist)
for i in tup:
print(i%3, end=",") Ans: 2,2,0,1,2,
25. Answer the following : 2
i) Name the package imported for connecting Python with MySQL database.
ii) What is the purpose of cursor object?
OR
What is difference between Primary key & Unique key.

SECTION C 3*5=15
26. Consider the following tables Trainer and Course: 3

a) What will be the output of the following statement?


SELECT * FROM TRAINER NATURAL JOIN COURSE;
b) Write the Outputs of the MySQL queries (i) to (iv) based on the given above
tables:
i. SELECT DISTINCT(CITY) FROM TRAINER WHERE SALARY>80000;
ii. SELECT TID, COUNT(*), MAX(FEES) FROM COURSE GROUP BY TID
HAVING COUNT(*)>1;
iii.SELECT T.TNAME, C.CNAME FROM TRAINER T, COURSE C
WHERET.TID=C.TID AND T.FEES<10000;
iv. SELECT COUNT(CITY),CITY FROM TRAINER GROUP BY CITY;
Ans: Ans:
a. Combine the rows from the table for NATURAL JOIN based on the common column TID
b.
i. Mumbai, Chandigarh
ii. 101 2 20000
iii. MEENAKSHI DDTP
iv. 2 Mumbai
2 Delhi
1 Chandigarh
1 Chennai
27. Write a method/function COUNTLINES_ET() in python to read lines from a text file 3
REPORT.TXT, and COUNT those lines which are starting either with ‘E’ or starting
with ‘T’ and display the Total count separately.
For example:
If REPORT.TXT consists of
“ENTRY LEVEL OF PROGRAMMING CAN BE LEARNED FROM PYTHON. ALSO, IT
IS VERY FLEXIBLE LANGUGAE. THIS WILL BE USEFUL FOR VARIETY OF
USERS.”
Then, Output will be:
No. of Lines with E: 1
No. of Lines with T: 1
OR
Write a method/ function SHOW_TODO() in python to read contents from a text file
ABC.TXT and display those lines which have occurrence of the word ‘‘TO’’ or ‘‘DO’’.
For example :

If the content of the file is


“THIS IS IMPORTANT TO NOTE THAT
SUCCESS IS THE RESULT OF HARD WORK.
WE ALL ARE EXPECTED TO DO HARD WORK.
AFTER ALL EXPERIENCE COMES FROM HARDWORK.”
The method/function should display:
THIS IS IMPORTANT TO NOTE THAT
WE ALL ARE EXPECTED TO DO HARD WORK.
Ans :def COUNTLINES_ET():
fobj = open("REPORT.txt")
lines = fobj.readlines()
lineE=0
lineT=0
for i in lines:
if i[0]=="E":
lineE+=1
elif i[0]=="T":
lineT+=1
print("No. of lines with E: ", lineE)
print("No. of lines with T: ", lineT)
COUNTLINES_ET()
OR
def SHOW_TODO():
fobj = open("ABC.txt")
for i in fobj:
if "TO" in i or "DO" in i:
print(i)
SHOW_TODO()
28. Write the outputs of the SQL queries (i) to (iv) based on the relations Teacher and 3
Posting given below:
a) 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.Department = Posting.Department AND
Posting.Place=”Delhi”;
iv. SELECT Gender, COUNT(Gender) FROM Teacher GROUP BY Gender;
b) Write the command to view the description of the table Teacher.
Ans i
Department Count(*)
History 3
Computer Sc 2
Mathematics 3

ii Max – 31/07/2018 or 2018-07-31 Min-05/09/2007 or 2007-09-05


iii
Name Department Place
Jugal Computer Sc Delhi
Shiv Om Computer Sc Delhi
iv
Gender Count(Gender)
M 5
F 3
b. DESC Teacher;
29. Python funtionoddeve(L) to print positive numbers in a list L. 3
Example:
Input: [10, -1, 15, 9, -6, 2, -9, 8,3]
Output: [10, 15, 9, 2, 8,3]
Ans:
def oddeve(myList):
print("All positive numbers of the list : ")
for ele in myList:
if ele >= 0:
print(ele, end = " ")
30. Write a function AddCustomer(Customer) in Python to add a new Customer 3
information into the stack (list) CStack and display the information.
OR
Write a function DeleteCustomer() to delete a Customer information from a list of
CStack. The function delete the name of customer from the stack.
Example: If the stack contains [“Abhinav”,”Vimank”],
the output should be:
Vimank
Abhinav
Ans:
def AddCustomer(Customer):
CStake.append(Customer)
if len(CStack)==0:
print (“Empty Stack”)
else:
print (CStack)
OR
def DeleteCustomer():
if (CStack ==[]):
print(“Stack empty!”)
else:
print(“Record deleted:”,CStack.pop()
SECTION-D 5*3=15
31. Prithvi Training Institute is planning to set up its centre in Jaipur with four specialized 5
blocks for Medicine, Management, Law courses along with an Admission block in
separate buildings. The physical distances between these blocks and the number of
computers to be installed in these blocks are given below. You as a network expert
have to answer the queries raised by their board of directors as given in (i) to (v).

i. Suggest the most suitable location to install the main server of this institution to
get efficient connectivity.
ii. Suggest by drawing the best cable layout for effective network connectivity of the
blocks having server with all the other blocks.
iii. Suggest the devices to be installed in each of these buildings for connecting
computers installed within the building out of the following:
Modem, Switch, Gateway, Router
iv. Suggest the most suitable wired medium for efficiently connecting each computer
installed in every building out of the following network cables: Coaxial Cable,
Ethernet Cable, Single Pair, Telephone Cable
v. Suggest the type of network implemented here.
Ans:
(i) Admin Block. Because of Maximum Computers.
(iii) Switch
(iv) Ethernet cable
(v) LAN
32. a). Write the output of following python code:def result(s): 5
n = len(s)
m=''
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m + s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m= m + s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m + '#'
print(m)
result('Cricket') Ans: cCICKEe

b). Avni is trying to connect Python with MySQL for her project. Help her to write the
python statement on the following:
i. Name the library, which should be imported to connect MySQL with Python.
ii. Name the function, used to run SQL query in Python.
iii. Write Python statement of connect function having the arguments values as
: Host name :192.168.11.111
User : root
Password: Admin
Database : MYPROJECT
Ans:
i. import mysql.connector
ii. cursorobj.execute(query)
iii. mysql.connector.connect(host= “192.168.11.111”, user = “root”, passwd =
“Admin”, database= “MYPROJECT”)
OR
a). Write the output of following python code:
Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+"*"
print(Msg3)
Ans: G*L*TME
b). Your friend Jagdish is writing a code to fetch data from a database Shop and
table name Products using Python. He has written incomplete code. You have to help
him write complete code:
import _mysql.connector_ as m # Statement-1
object1 =
m.connect(host="localhost",user="root",password="root",database="Shop")
object2 = object1.cursor()_____ # Statement-2
query = '''SELECT * FROM Products WHERE NAME LIKE "A%";'''
object2._execute____(query) # Statement-3
object1.close()

33. a. What is the advantage of using pickle module? 5


b. Write a program to write into a CSV file “one.csv” Rollno, Name and Marks
separated by comma. It should have header row and then take input from the user
for all following rows. The format of the file should be as shown if user enters 2
records. Roll.No,Name,Marks
20,Ronit,67
56,Nihir,69
Ans:
Pickle module helps us to work with Binary files from Python program.
import csv
f1=open('one.csv','w',newline= “”)
w1=csv.writer(f1,delimiter = ",")
w1.writerow(['Roll.No', 'Name', 'Marks'])
while True:
print ("Enter 1 to continue adding, 0 to exit")
op = int(input("Enter Option"))
if (op == 1):
rollno = int(input("Enter Roll No"))
name = input("Enter Name")
marks = int(input("Enter Marks"))
wlist = [rollno,name,marks]
w1.writerow(wlist)
elif op == 0:
break;
f1.close()
OR
a. What is difference between tell() and seek() methods?
b. Write a program to read all content of “student.csv” and display records of only
those students who scored more than 80 marks. Records stored in students is in
format : [Rollno, Name, Marks]
Ans: tell(): It returns the current position of cursor in file
seek(): Changes the cursor position by bytes as specified by the offset.
import csv
f=open("student.csv","r")
d=csv.reader(f)
next(f)
print("Students Scored More than 80")
print()
for i in d:
if int(i[2])>80:
print("Roll Number =", i[0])
print("Name =", i[1])
print("Marks=", i[2])
f.close( )
SECTION-E 4*2=8
34. Aman creates a table Emp 4

Based on the data given above answer the following questions:


(i) Identify the most appropriate column, which can be considered as Primary key.
(ii) If one column is added and 2 rows are deleted from the table EMP, what will be
the new degree and cardinality of the above table?
(iii) Write the statements to:
a. Insert the following record into the table
EmpNo- 8, Name- Ravi, Dept- Sales, Design- Mgr, Gender- M,
Salary – 34000, City- Delhi .
b. Increase the Salary of the Employees who are in Acct department by 3%.
OR (Option for part iii only)
(iii) Write the statements to:
a. Delete the record of Employees who lives in Delhi.
b. Add a column MobNo in the table with datatype as
varchar with 10 characters
Ans:
a. Degree: 4 Cardinality: 6
b. TID as this is different for every row/tuple in the table
c.
i. INSERT INTO TRAINER (TID, TNAME, CITY, HIREDATE, SALARY)
VALUES(107,’Bhoomi’,’Delhi’,”2001-12-15”,90000);
ii. UPDATE TRAINER SET SALARY = SALARY*101 WHERE SALARY > 80000;

OR
i. DELETE FROM TRAINER WHERE TNAME = “Richa”;
ii. ALTER TABLE TRAINER ADD Remarks VARCHAR(50);

35 Priti of class 12 is writing a program to create a CSV file “emp.csv”. She has written 4
the following code to read the content of file emp.csv and display the employee
record whose name begins from “S‟ also show no. of employee with first letter “S‟
out of total record. As a programmer, help her to successfully execute the given task.
Consider the following CSV file (emp.csv):
1,Peter,3500
2,Scott,4000
3,Harry,5000
4,Michael,2500
5,Sam,4200
import ____csv_ #Line-1
defsnames():
with open( emp.csv”, “r” ___) as csvfile: #Line-2
myreader = csv._reader__ (csvfile, delimiter=",") # Line-3
count_rec=0
count_s=0
for row in myreader:
if row[1][0].lower() == "s":
print(row[0],",",row[1],",",row[2])
count_s += 1
count_rec += 1
print(count_rec, count_s)
i. What should be written in Line-1?
ii. In which mode should Priti open the file to print the data? Read mode
iii. What should be written in Line-2 and Line-3?

You might also like