0% found this document useful (0 votes)
200 views31 pages

Sample Questions Set

The document contains 50 multiple choice questions related to Python programming. The questions cover a range of Python topics including data types, operators, functions, files, exceptions, classes and more. Each question is followed by 4 possible answer choices with one correct answer.

Uploaded by

Night Fury
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
200 views31 pages

Sample Questions Set

The document contains 50 multiple choice questions related to Python programming. The questions cover a range of Python topics including data types, operators, functions, files, exceptions, classes and more. Each question is followed by 4 possible answer choices with one correct answer.

Uploaded by

Night Fury
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 31

Sample Questions Set

Q.1 Find the invalid identifier from the following


A. none B. address C. Name D. pass
Q.2 Consider a declaration L = (1, 'Python', '3.14').
Which of the following represents the data type of L?
a. list b. tuple c. dictionary d. string
Q.3 Given a Tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output of print (tup1 [3:7:2])?
a. (40,50,60,70,80) b. (40,50,60,70) c. [40,60] d. (40,60)
Q.4 Which of the following option is not correct?
a. if we try to read a text file that does not exist, an error occurs.
b. if we try to read a text file that does not exist, the file gets created.
c. if we try to write on a text file that does not exist, no error occurs.
d. if we try to write on a text file that does not exist, the file gets created.
Q.5 Which of the following options can be used to read the first line of a text file Myfile.txt?
a. myfile = open('Myfile.txt'); myfile.read()
b. myfile = open('Myfile.txt','r'); myfile.read(n)
c. myfile = open('Myfile.txt'); myfile.readline()
d. myfile = open('Myfile.txt'); myfile.readlines()
Q.6 Assume that the position of the file pointer is at the beginning of 3rd line in a text file. Which
of the following option can be used to read all the remaining lines?
a. myfile.read()
b. myfile.read(n)
c. myfile.readline()
d. myfile.readlines()
Q.7 A text file student.txt is stored in the storage device. Identify the correct option out of the
following options to open the file in read mode.
i. myfile = open('student.txt','rb')
ii. myfile = open('student.txt','w')
iii. myfile = open('student.txt','r')
iv. myfile = open('student.txt')
a. only I b. both i and iv c. both iii and iv d. both i and iii

Q8 The return type of the input() function is


a. string b. integer c. list d. tuple
Q.9 Which of the following operator cannot be used with string data type?
a. + b. in c. * d. /
Q.10 Consider a tuple tup1 = (10, 15, 25, and 30). Identify the statement that will result in an error.
a. print(tup1[2]) b. tup1[2] = 20 c. print(min(tup1)) d. print(len(tup1))
Q.11 Which of the following statement is incorrect in the context of binary files?
a. Information is stored in the same format in which the information is held in memory.
b. No character translation takes place
c. Every line ends with a new line character
d. pickle module is used for reading and writing
Q.12 What is the significance of the tell() method?
a. tells the path of file
b. tells the current position of the file pointer within the file
c. tells the end position within the file
d. checks the existence of a file at the desired location
Q13 Which of the following statement is true?
a. pickling creates an object from a sequence of bytes
b. pickling is used for object serialization
c. pickling is used for object deserialization
d. pickling is used to manage all types of files in Python
Q.14 Syntax of seek function in Python is myfile.seek(offset, reference_point) where myfile is
the file object. What is the default value of reference_point?
a. 0
b. 1
c. 2
d. 3
Q.15 Which of the following components are part of a function header in Python?
a. Function Name
b. Return Statement
c. Parameter List
d. Both a and c

Q.16 Which of the following function header is correct?


a. def cal_si(p=100, r, t=2)
b. def cal_si(p=100, r=8, t)
c. def cal_si(p, r=8, t)
d. def cal_si(p, r=8, t=2)
Q.17 Which of the following is the correct way to call a function?
a. my_func()
b. def my_func()
c. return my_func
d. call my_func()
Q.18 Which of the following character acts as default delimiter in a csv file?
a. (colon) :
b. (hyphen) -
c. (comma) ,
d. (vertical line) |
Q.19 Syntax for opening Student.csv file in write mode is
myfile = open("Student.csv","w",newline='').
What is the importance of newline=''?
a. A newline gets added to the file
b. Empty string gets appended to the first line.
c. Empty string gets appended to all lines.
d. EOL translation is suppressed
Q.20 What is the correct expansion of CSV files?
a. Comma Separable Values
b. Comma Separated Values
c. Comma Split Values
d. Comma Separation Values
Q.21 Which of the following is not a function / method of csv module in Python?
a. read()
b. reader()
c. writer()
d. writerow()

Q.22 Which one of the following is the default extension of a Python file?
a. .exe
b. .p++
c. .py
d. .p
Q.23 Which of the following symbol is used in Python for single line comment?
a. /
b. /*
c. //
d. #
Q.24 Which of the following statement opens a binary file record.bin in write mode and writes
data from a list lst1 = [1,2,3,4] on the binary file?
a. with open('record.bin','wb') as myfile:
pickle.dump(lst1,myfile)
b. with open('record.bin','wb') as myfile:
pickle.dump(myfile,lst1)
c. with open('record.bin','wb+') as myfile:
pickle.dump(myfile,lst1)
d. with open('record.bin','ab') as myfile:
pickle.dump(myfile,lst1)
Q.25 Which of these about a dictionary is false?
a) The values of a dictionary can be accessed using keys
b) The keys of a dictionary can be accessed using values
c) Dictionaries aren’t ordered
d) Dictionaries are mutable
Q.26 What is the output of following code:
T=(100)
print(T*2)
a. Syntax error
b. (200,)
c. 200
d. (100,100)

Q.27 Suppose content of 'Myfile.txt' is:


Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky
What will be the output of the following code?
myfile = open("Myfile.txt")
data = myfile.readlines()
print(len(data))
myfile.close()
a. 3
b. 4
c. 5
d. 6
Q.28 Identify the output of the following Python statements.
x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)
a. 12.0
b. 13.0
c. 14.0
d. 15.0
Q.29 Identify the output of the following Python statements.
x=2
while x < 9:
print(x, end='')
x=x+1
a. 12345678
b. 123456789
c. 2345678
d. 23456789

Q.30 Identify the output of the following Python statements.


b=1
for a in range(1, 10, 2):
b += a + 2
print(b)
a. 31
b. 33
c. 36
d. 39
Q.31 Identify the output of the following Python statements.
lst1 = [10, 15, 20, 25, 30]
lst1.insert( 3, 4)
lst1.insert( 2, 3)
print (lst1[-5])
a. 2
b. 3
c. 4
d. 20
Q.32 Raghav is trying to write a tuple tup1 = (1,2,3,4,5) on a binary file test.bin. Consider the
following code written by him.
import pickle
tup1 = (1,2,3,4,5)
myfile = open("test.bin",'wb')
pickle._______ #Statement 1
myfile.close()
Identify the missing code in Statement 1.
a. dump(myfile,tup1)
b. dump(tup1, myfile)
c. write(tup1,myfile)
d. load(myfile,tup1)
Q.33 A binary file employee.dat has following data
Empno empname Salary
101 Anuj 50000
102 Arijita 40000
103 Hanika 30000
104 Firoz 60000
105 Vijaylakshmi 40000
def display(eno):
f=open("employee.dat","rb")
totSum=0
try:
while True:
R=pickle.load(f)
if R[0]==eno:
__________ #Line1
totSum=totSum+R[2]
except:
f.close()
print(totSum)
When the above mentioned function, display (103) is executed, the output displayed is
190000.
Write appropriate jump statement from the following to obtain the above output.
a. jump
b. break
c. continue
d. return
Q.34 What will be the output of the following Python code?
def add (num1, num2):
sum = num1 + num2
sum = add(20,30)
print(sum)
a. 50
b. 0
c. Null
d. None

Q.35 Evaluate the following expression and identify the correct answer.
16 - (4 + 2) * 5 + 2**3 * 4
a. 54
b. 46
c. 18
d. 32
Q.36 What will be the output of the following code?
def my_func(var1=100, var2=200):
var1+=10
var2 = var2 - 10
return var1+var2
print(my_func(50),my_func())
a. 100 200
b. 150 300
c. 250 75
d. 250 300
Q.37 What will be the output of the following code?
value = 50
def display(N):
global value
value = 25
if N%7==0:
value = value + N
else:
value = value - N
print(value, end="#")
display(20)
print(value)
a. 50#50
b. 50#5
c. 50#30
d. 5#50#

Q.38 What will be the output of the following code?


import random
List=["Delhi","Mumbai","Chennai","Kolkata"]
for y in range(4):
x = random.randint(1,3)
print(List[x],end="#")
a. Delhi#Mumbai#Chennai#Kolkata#
b. Mumbai#Chennai#Kolkata#Mumbai#
c. Mumbai# Mumbai #Mumbai # Delhi#
d. Mumbai# Mumbai #Chennai # Mumbai
Q39 What is the output of the following code snippet?
def ChangeVal(M,N):
for i in range(N):
if M[i]%5 == 0:
M[i]//=5
if M[i]%3 == 0:
M[i]//=3
L = [25,8,75,12]
ChangeVal(L,4)
for i in L:
print(i,end="#")
a) 5#8#15#4#
b) 5#8#5#4#
c) 5#8#15#14#
d) 5#18#15#4#
Q.40 Suppose content of 'Myfile.txt' is
Humpty Dumpty sat on a wall
Humpty Dumpty had a great fall
All the king's horses and all the king's men
Couldn't put Humpty together again
What will be the output of the following code?
myfile = open("Myfile.txt")
record = myfile.read().split()
print(len(record))
myfile.close()
a. 24
b. 25
c. 26
d. 27
Q.41 Find the output of the following code:
Name="PythoN3.1"
R=""
for x in range(len(Name)):
if Name[x].isupper():
R=R+Name[x].lower()
elif Name[x].islower():
R=R+Name[x].upper()
elif Name[x].isdigit():
R=R+Name[x-1]
else:
R=R+"#"
print(R)
a. pYTHOn##@
b. pYTHOnN#@
c. pYTHOn#@
d. pYTHOnN@#
Q.42 Suppose content of 'Myfile.txt' is
Honesty is the best policy.
What will be the output of the following code?
myfile = open("Myfile.txt")
x = myfile.read()
print(len(x))
myfile.close()
a. 5
b. 25
c. 26
d. 27
Q.43 Suppose content of 'Myfile.txt' is
Culture is the widening of the mind and of the spirit.
What will be the output of the following code?
myfile = open("Myfile.txt")
x = myfile.read()
y = x.count('the')
print(y)
myfile.close()
a. 2
b. 3
c. 4
d. 5
Q.44 What will be the output of the following code?
x=3
def myfunc():
global x
x+=2
print(x, end=' ')
print(x, end=' ')
myfunc()
print(x, end=' ')
a. 3 3 3
b. 3 4 5
c. 3 3 5
d. 3 5 5
Q.45 Suppose content of 'Myfile.txt' is
Ek Bharat Shreshtha Bharat
What will be the output of the following code?
myfile = open("Myfile.txt")
vlist = list("aeiouAEIOU")
vc=0
x = myfile.read()
for y in x:
if(y in vlist):
vc+=1
print(vc)
myfile.close()
a. 6
b. 7
c. 8
d. 9
Q.46 Suppose content of 'Myfile.txt' is
Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky
Twinkle twinkle little star
What will be the output of the following code?
myfile = open("Myfile.txt")
line_count = 0
data = myfile.readlines()
for line in data:
if line[0] == 'T':
line_count += 1
print(line_count)
myfile.close()
a. 2
b. 3
c. 4
d. 5
Q.47 Consider the following directory structure.
Suppose root directory (School) and present working directory are the same. What will
be the absolute path of the file Syllabus.jpg?
a. School/syllabus.jpg
b. School/Academics/syllabus.jpg
c. School/Academics/../syllabus.jpg
d. School/Examination/syllabus.jpg
Q.48 Assume the content of text file, 'student.txt' is:
Arjun Kumar
Ismail Khan
Joseph B
Hanika Kiran
What will be the data type of data_rec?
myfile = open("Myfile.txt")
data_rec = myfile.readlines()
myfile.close()
a. string
b. list
c. tuple
d. dictionary
Q49 What will be the output of the following code?
tup1 = (1,2,[1,2],3)
tup1[2][1]=3.14
print(tup1)
a. (1,2,[3.14,2],3)
b. (1,2,[1,3.14],3)
c. (1,2,[1,2],3.14)
d. Error Message
Rohit, a student of class 12, is learning CSV File Module in Python. During examination,
he has been assigned an incomplete python code (shown below) to create a CSV File
'Student.csv' (content shown below). Help him in completing the code which creates the
desired CSV File.
CSV File
1,AKSHAY,XII,A
2,ABHISHEK,XII,A
3,ARVIND,XII,A
4,RAVI,XII,A
5,ASHISH,XII,A
Incomplete Code
import _____ #Statement-1
fh = open(_____, _____, newline='') #Statement-2
stuwriter = csv._____ #Statement-3
data = [ ]
header = ['ROLL_NO', 'NAME', 'CLASS', 'SECTION']
data.append(header)
for i in range(5):
roll_no = int(input("Enter Roll Number : "))
name = input("Enter Name : ")
Class = input("Enter Class : ")
section = input("Enter Section : ")
rec = [ _____ ] #Statement-4
data.append(_____) #Statement-5
stuwriter. _____ (data) #Statement-6
fh.close()
Q50 Identify the suitable code for blank space in the line marked as Statement-1.
a) csv file
b) CSV
c) csv
d) cvs
Q.51 Identify the missing code for blank space in line marked as Statement-2.
a) "Student.csv","wb"
b) "Student.csv","w"
c) "Student.csv","r"
d) "Student.cvs","r"
Q.52 Choose the function name (with argument) that should be used in the blank space of line
marked as Statement-3.
a) reader(fh)
b) reader(MyFile)
c) writer(fh)
d) writer(MyFile)
Q.53 Identify the suitable code for blank space in line marked as Statement-4.
a) 'ROLL_NO', 'NAME', 'CLASS', 'SECTION'
b) ROLL_NO, NAME, CLASS, SECTION
c) 'roll_no','name','Class','section'
d) roll_no,name,Class,section
Q.54 Identify the suitable code for blank space in the line marked as Statement-5.
a) data
b) record
c) rec
d) insert
Q.55 Choose the function name that should be used in the blank space of line marked as
Statement-6 to create the desired CSV File?
a) dump()
b) load()
c) writerows()
d) writerow()
Q.56 Find the invalid identifier from the following
a) MyName b) True c) 2ndName d) My_Name
Q.57 Given the lists L=[1,3,6,82,5,7,11,92] , write the output of print(L[2:5]) 1.
3 Write the full form of CSV.
4 Identify the valid arithmetic operator in Python from the following.
a) ? b) < c) ** d) and
Q.58 Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is
incorrect?
a) print(T[1])
b) T[2] = -29
c) print(max(T))
d) print(len(T))
Q.59 Write a statement in Python to declare a dictionary whose keys are 1, 2, 3
and values are Monday, Tuesday and Wednesday respectively.
Q.60 A tuple is declared as
T = (2,5,6,9,8)
What will be the value of sum(T)?

Q.61Name the built-in mathematical function / method that is used to return an


absolute value of a number.
Q.62Name the protocol that is used to send emails.
Q.63 Your friend Ranjana complaints that somebody has created a fake profile on
Facebook and defaming her character with abusive comments and pictures.
Identify the type of cybercrime for these situations.
Q.64 In SQL, name the clause that is used to display the tuples in ascending order
of an attribute.
Q.65 In SQL, what is the use of IS NULL operator?
Q.66 Write any one aggregate function used in SQL. 1
Q.67Which of the following is a DDL command?
a) SELECT b) ALTER c) INSERT d) UPDATE
Q.68 Name The transmission media best suitable for connecting to hilly areas.
Q.69 Identify the valid declaration of L:
L = [‘Mon’, ‘23’, ‘hello’, ’60.5’]
a. dictionary b. string c.tuple d. list
Q.70 If the following code is executed, what will be the output of the following
code?
name="ComputerSciencewithPython"
print(name[3:10])
Q71 In SQL, write the query to display the list of tables stored in a database. 1
Q.72 Write the expanded form of Wi-Fi. 1
Q73 Which of the following types of table constraints will prevent the entry of
duplicate rows?
a) Unique
b) Distinct
c) Primary Key
d) NULL
Q.74 Rearrange the following terms in increasing order of data transfer rates.
Gbps, Mbps, Tbps, Kbps, bps
Q.75 22 A departmental store MyStore is considering to maintain their inventory
using SQL to store the data. As a database administer, Abhay has decided
that :• Name of the database - mystore
• Name of the table - STORE
• The attributes of STORE are as follows:
ItemNo - numeric
ItemName – character of size 20
Scode - numeric
Quantity – numeric
Table : STORE
ItemNo ItemName Scode Quantity
2005 Sharpener Classic 23 60
2003 Ball Pen 0.25 22 50
2002 Get Pen Premium 21 150
2006 Get Pen Classic 21 250
2001 Eraser Small 22 220
2004 Eraser Big 22 110
2009 Ball Pen 0.5 21 180
Q.76 Identify the attribute best suitable to be declared as a primary key, 1
Q.77 Write the degree and cardinality of the table STORE. 1
Q.78 Insert the following data into the attributes ItemNo, ItemName and
SCode respectively in the given table STORE.
ItemNo = 2010, ItemName = “Note Book” and Scode = 25
Q.79 Abhay want to remove the table STORE from the database MyStore.
Which command will he use from the following:
a) DELETE FROM store;
b) DROP TABLE store;
c) DROP DATABASE mystore;
d) DELETE store FROM mystore;
Q.80 Now Abhay wants to display the structure of the table STORE, 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.
Q.81 Ranjan Kumar of class 12 is writing a program to create a CSV file “user.csv”
which will contain user name and password for some entries. He has written
the following code. As a programmer, help him to successfully execute the
given task.
import _____________ # Line 1
def addCsvFile(UserName,PassWord): # to write / add data into the
CSV file
f=open(' user.csv','________') # Line 2
Page 5 of 11
newFileWriter = csv.writer(f)
newFileWriter.writerow([UserName,PassWord])
f.close()
#csv file reading code
def readCsvFile(): # to read data from CSV file
with open(' user.csv','r') as newFile:
newFileReader = csv._________(newFile) # Line 3
for row in newFileReader:
print (row[0],row[1])
newFile.______________ # Line 4
addCsvFile(“Arjun”,”123@456”)
addCsvFile(“Arunima”,”aru@nima”)
addCsvFile(“Frieda”,”myname@FRD”)
readCsvFile() #Line 5
Q.82 Name the module he should import in Line 1.
Q.83In which mode, Ranjan should open the file to add data into the file 1
Q.84 Fill in the blank in Line 3 to read the data from a csv file. 1
Q.85 Fill in the blank in Line 4 to close the file.
(Q.86) Write the output he will obtain while executing Line 5.
Q.87 Evaluate the following expressions:
a) 6 * 3 + 4**2 // 5 – 8
b) 10 > 5 and 7 > 12 or not 18 > 3
Q.88 Differentiate between Viruses and Worms in context of networking and data
communication threats.OR Differentiate between Web server and web browser. Write any two popular
web browsers.
Q.89 Expand the following terms:
a. SMTP b. XML c. LAN d. IPR

Q.90Differentiate between actual parameter(s) and a formal parameter(s) with a


suitable example for each.
OR
Explain the use of global key word used in a function with the help of a
suitable example.
Q.91 Rewrite the following code in Python after removing all syntax error(s).
Underline each correction done in the code.
Value=30
for VAL in range(0,Value)
If val%4==0:
print (VAL*4)
Elseif val%5==0:
print (VAL+3)
else
print(VAL+10)
Q.92 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 variables Lower and
Upper.
import random
AR=[20,30,40,50,60,70];
Lower =random.randint(1,3)
Upper =random.randint(2,4)
for K in range(Lower, Upper +1):
print (AR[K],end=”#“)
(i) 10#40#70# (ii) 30#40#50# (iii) 50#60#70# (iv)40#50#70#
Q.93 What do you understand by Candidate Keys in a table? Give a suitable
example of Candidate Keys from a table containing some meaningful data.
31 Differentiate between fetchone() and fetchall() methods with suitable
examples for each.
Q.94 Write the full forms of DDL and DML. Write any two commands of DML in
SQL.

Q.94 Find and write the output of the following Python code:
def Display(str):
m=""
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
else:
if i%2==0:
m=m+str[i-1]
else:
m=m+"#"
print(m)
Display('Fun@Python3.0')
Q.95 Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers
and n is a numeric value by which all elements of the list are shifted to left.
Sample Input Data of the list
Arr= [ 10,20,30,40,12,11], n=2
Output
Arr = [30,40,12,11,10,20]
Q.96 Write a function in Python that counts the number of “Me” or “My” words
present in a text file “STORY.TXT”.
If the “STORY.TXT” contents are as follows:
My first book
was Me and
My Family. It
gave me
chance to be
Known to the
world.
The output of the function should be:
Count of Me/My in file: ?
OR
Write a function AMCount() in Python, which should read each character
of a text file STORY.TXT, should count and display the occurance of
alphabets A and M (including small cases a and m too).
Example:
If the file content is as follows:
Updated information
As simplified by official websites.
Q.97The EUCount() function should display the output as:?
Q.98 Write the outputs of the SQL queries (i) to (iii) based on the relations Teacher
and Posting given below:
Table : Teacher
T_ID Name Age Department Date_of_join Salary Gender
1 Jugal 34 Computer Sc 10/01/2017 12000 M
2 Sharmila 31 History 24/03/2008 20000 F
3 Sandeep 32 Mathematics 12/12/2016 30000 M
4 Sangeeta 35 History 01/07/2015 40000 F
5 Rakesh 42 Mathematics 05/09/2007 25000 M
6 Shyam 50 History 27/06/2008 30000 M
7 Shiv Om 44 Computer Sc 25/02/2017 21000 M
8 Shalakha 33 Mathematics 31/07/2018 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 Teachr, Posting WHERE
Teacher.Department = Posting.Department AND
Posting.Place=”Delhi”;
Q.99 Write a function in Python PUSH(Arr), where Arr is a list of numbers. From
this list push all numbers divisible by 5 into a stack implemented by using a
list. Display the stack if it has at least one element, otherwise display
appropriate error message.
OR
Write a function in Python POP(Arr), where Arr is a stack implemented by a
list of numbers. The function returns the value deleted from the stack.
Q.100 MyPace University is setting up its academic blocks at Naya Raipur
and is planning to set up a network. The University has 3 academic
blocks and one Human Resource Center as shown in the diagram
below:
Center to Center distances between various blocks/center is as follows:
Law Block to business Block 40m
Law block to Technology Block 80m
Law Block to HR center 105m
Business Block to technology
Block
30m
Business Block to HR Center 35m
Technology block to HR center 15m
Number of computers in each of the blocks/Center is as follows:
Law Block 15
Technology Block 40
HR center 115
Business Block 25
a) Suggest the most suitable place (i.e., Block/Center) to install
the server of this University with a suitable reason.
b) Suggest an ideal layout for connecting these blocks/centers for a
wired connectivity.
c) Which device will you suggest to be placed/installed in each
of these blocks/centers to efficiently connect all the
computers within these blocks/centers.
d) Suggest the placement of a Repeater in the network
with justification.
e) The university is planning to connect its admission office in
Delhi, which is more than 1250km from university. Which
type of network out of LAN, MAN, or WAN will be formed?
Justify youranswer.
Q101 Write SQL commands for the following queries (i) to (v) based on the
relations Teacher and Posting given below:
Table : Teacher
T_ID Name Age Department Date_of_join Salary Gender
1 Jugal 34
Computer
Sc
10/01/2017 12000 M
2 Sharmila 31 History 24/03/2008 20000 F
3 Sandeep 32 Mathematics 12/12/2016 30000 M
4 Sangeeta 35 History 01/07/2015 40000 F
5 Rakesh 42 Mathematics 05/09/2007 25000 M
6 Shyam 50 History 27/06/2008 30000 M
7 Shiv Om 44
Computer
Sc
25/02/2017 21000 M
8 Shalakha 33 Mathematics 31/07/2018 20000 F
Table : Posting
P_ID Department Place
1 History Agra
2 Mathematics Raipur
3 Computer Science Delhi
i. To show all information about the teacher of History
department.
ii. To list the names of female teachers who are in Mathematics
department.
iii. To list the names of all teachers with their date of joining in
ascending order.
iv. To display teacher’s name, salary, age for male teachers only.
v. To display name, bonus for each teacher where bonus is 10%
of salary.
Q.102 A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price].
i. Write a user defined function CreateFile() to input data for a
record and add to Book.dat .
ii. Write a function CountRec(Author) in Python which accepts the
Author name as parameter and count and return number of
books by the given Author are stored in the binary file
“Book.dat”
OR
A binary file “STUDENT.DAT” has structure (admission_number, Name,
Percentage). Write a function countrec() in Python that would read contents
of the file “STUDENT.DAT” and display the details of those students whose
Percentage is above 75. Also display number of students scoring above 75%
Q.103 state weather true or false:
Variable declaration is implicit in Python.

Q.104 which of the following is invalid datatype in python.


(a) Set (b) None (c)Integer (d)Real

Q.105 Given the following dictionaries:

dict_exam={“Exam”:”AISSCE”, “Year”:2023} dict_result={“Total”:500, “Pass_Marks”:165}

Which statement will merge the contents of both dictionaries?

a. dict_exam.update(dict_result)

b. dict_exam + dict_result

c. dict_exam.add(dict_result)

d. dict_exam.merge(dict_result)

Q.106 Consider the given expression:

not True and False or True

Which of the following will be the correct output if the given expression is evaluated?

(a) True

(b) False

(c) NONE

(d) NULL
Q.107 Select the correct output of the code:

a = “Year 2022 at All the best”

a = a.split(‘2’)

b = a[0] + “. ” + a[1] + “. ” + a[3]

print (b)

(a) Year . 0. at All the best

(b) Year 0. at All the best

(c) Year . 022. at All the best

(d) Year . 0. at all the best

Q.108 Which of the following mode in file opening statement results or

generates an error if the file does not exist?

(a) a+        (b) r+         (c) w+         (d) None of the above

Q.109 Fill in the blank:

………………….command is used to remove the primary key from the table in SQL.

(a) update           (b)remove            (c) alter                (d)drop

Q.110 Which of the following commands will delete the table from MYSQL

database?

(a)DELETETABLE

(b)DROPTABLE

(c)REMOVETABLE

(d) ALTER TABLE


Q.111. Which of the following statement(s) would give an error after executing the following code?

(a)Statement3

(b)Statement4

(c)Statement5

(d) Statement 4 and 5

Q112. Fill in the blank:……………………is a non-key attribute, whose values are derived from the primary key of some other

table.

(a)PrimaryKey

(b)ForeignKey

(c)CandidateKey

(d) Alternate Key

113. The correct syntax of seek() is:

(a) file_object.seek(offset [, reference_point])

(b) seek(offset [, reference_point])

(c) seek(offset, file_object)

(d) seek.file_object(offset)

Q.114. Fill in the blank:

The SELECT statement when combined with…………………. clause returns records without repetition.
(a) DESCRIBE

(b) UNIQUE

(c) DISTINCT

(d) NULL

115. Fill in the blank:

……………………is a communication methodology designed to deliver both voice and multimedia communications over Internet

protocol. (a) VoIP              (b) SMTP          (c) PPP                (d)HTTP

q.116. What will the following expression be evaluated to in Python?

print(15.0 / 4 + (8 + 3.0))

(a) 14.75             (b)14.0            (c) 15        (d) 15.5 1

117. Which function is used to display the total number of records from table in a database?

(a) sum(*)

(b) total(*)

(c) count(*)

(d) return(*)

118. To establish a connection between Python and SQL databases, connect() is used. Which of the following arguments may

not necessarily be given while calling connect()?

(a) host

(b) database

(c) user

(d) password

Q119 and 120are 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

Q.121. Assertion (A):- If the arguments in the function call statement match the number and order of arguments as defined

in the function definition, such arguments are called positional arguments.


Reasoning (R):- During a function call, the argument list first contains default argument(s) followed by positional

argument(s).

Q122. Assertion (A): CSV (Comma Separated Values) is a file format for data storage that looks like a text file.

Reason (R): The information is organized with one record on each line and each field is separated by comma.

122. Rao has written a code to input a number and check whether it is prime or not. His code is having errors. Rewrite the

correct code and underline the corrections made.

Q123. Write two points of difference between Circuit Switching and Packet Switching. OR

Write two points of difference between XML and HTML.

Q124. (a) Given is a Python string declaration:


myexam=”@@CBSE Examination 2022@@”

Write the output of: print(myexam[::-2])

(b) Write the output of the code given below:

my_dict = {“name”: “Aman”, “age”: 26} my_dict[‘age’] = 27 my_dict[‘address’] = “Delhi” print(my_dict.items()) 1

Q125. Explain the use of ‘Foreign Key’ in a Relational Database Management System. Give example to support your answer.
Q126 (a) Write the full forms of the following:

(i) SMTP (ii) PPP

(b) What is the use of TELNET?

Q127. Predict the output of the Python code given below:

OR

Predict the output of the Python code given below:


Q128. Differentiate between count() and count(*) functions in SQL with appropriate example.

OR

Categorize the following commands as DDL or DML: INSERT, UPDATE, ALTER, DROP 2

Q129. (a) Consider the following tables – Bank_Account and Branch:

ACode Name Type

A01 Amrita Savings

A02 Parthodas Current

A03 Miraben Current

Table: Branch

ACode City

A01 Delhi

A02 Mumbai

A01 Nagpur
What will be the output of the following statement?

SELECT * FROM Bank_Account NATURAL JOIN Branch;

(b) Write the output of the queries (i) to (iv) based on the table, TECH_COURSE given below:

(i) SELECT DISTINCT TID FROM TECH_COURSE;

(ii) SELECT TID, COUNT(*), MIN(FEES) FROM TECH_COURSE GROUP BY TID HAVING COUNT(TID)>1;

(iii) SELECT CNAME FROM TECH_COURSE WHERE FEES>15000 ORDER BY CNAME;

(iv) SELECT AVG(FEES) FROM TECH_COURSE WHERE FEES BETWEEN 15000 AND 17000;

Q.130. Write a method COUNTLINES() in Python to read lines from text file

‘TESTFILE.TXT’ and display the lines which are not starting with any vowel. Example:If the file content is as follows:
An apple a day keeps the doctor away. We all pray for everyone’s safety.
A marked difference will come in our country.

The COUNTLINES() function should display the output as:

The number of lines not starting with any vowel – 1


OR

Write a function ETCount() in Python, which should read each character of a text file “TESTFILE.TXT” and then count and
display the count of occurrence of alphabets E and T individually (including small cases e and t too).

Example:

If the file content is as follows:

Today is a pleasant day. It might rain today.


It is mentioned on weather sites
The ETCount() function should display the output as: E or e: 6
T or t : 9

Q.131 (a) Write the outputs of the SQL queries (i) to (iv) based on the

relations Teacher and Placement given below:

Table : Teacher
Table : Placement

Q.132(i) SELECT Department, avg(salary) FROM Teacher GROUP BY Department;

Q.133ii) SELECT MAX(Date_of_Join),MIN(Date_of_Join) FROM Teacher;

Q.134ii) SELECT Name, Salary, T.Department, Place FROM Teacher T, Placement P WHERE T.Department = P.Department

AND Salary>20000;

Q135iv) SELECT Name, Place FROM Teacher T, Placement P

WHERE Gender =’F’ AND T.Department=P.Department;

(b) Write the command to view all tables in a database.

Q136. Write a function INDEX_LIST(L), where L is the list of elements passed as argument to the function. The function
returns another list named ‘index list’ that stores the indices of all Non-Zero Elements of L.

For example:

If L contains [12,4,0,11,0,56]

The indexList will have – [0,1,3,5] 3

Q137. A list contains the following record of a customer: [Customer_name, Phone_number, City]

Write the following user-defined functions to perform given operations on the stack named ‘status’:

(i) Push_element() – To Push an object containing name and

Phone number of customers who live in Goa to the stack

(ii) Pop_element() – To Pop the objects from the stack and display them. Also, display “Stack Empty” when there are no

elements in the stack.

For example:

If the lists of customer details are:


[“Gurdas”, “99999999999”,”Goa”]

[“Julee”, “8888888888”,”Mumbai”]

[“Murugan”,”77777777777”,”Cochin”] [“Ashmit”, “1010101010”,”Goa”]

The stack should contain [“Ashmit”,”1010101010”]

[“Gurdas”,”9999999999”]

The output should be: [“Ashmit”,”1010101010”]

[“Gurdas”,”9999999999”]

Stack Empty

OR

Q.138Write a function in Python, Push(SItem) where , SItem is a dictionary containing the details of stationary items–

{Sname:price}.

The function should push the names of those items in the stack who have price greater than 75. Also display the count of

elements pushed into the stack.

For example:

If the dictionary contains the following data:

Ditem={“Pen”:106,”Pencil”:59,”Notebook”:80,”Eraser”:25}

The stack should contain Notebook

Pen

The output should be:

The count of elements in the stack is 2

Q.139. MakeInIndia Corporation, an Uttarakhand based IT training company, is planning to set up training centres in various
cities in next 2 years. Their first campus is coming up in Kashipur district. At Kashipur campus, they are planning to have 3
different blocks for App development, Web designing and Movie editing. Each block has number of computers, which are
required to be connected in a network for communication, data and resource sharing. As a network consultant of this
company, you have to suggest the best network related solutions for them for issues/problems raised in question nos. (i) to
(v), keeping in mind the distances between various blocks/locations and other given parameters.
Q.140(i) Suggest the most appropriate block/location to house the SERVER in the Kashipur campus (out of the 3 blocks) to

get the best and effective connectivity. Justify your answer.

Q141(ii) Suggest a device/software to be installed in the Kashipur Campus to take care of data security.

Q142(iii) Suggest the best wired medium and draw the cable layout (Block to Block) to economically connect various blocks

within the

Kashipur Campus.
(iv) Suggest the placement of the following devices with appropriate reasons:

a. Switch / Hub

b. Repeater

(v) Suggest a protocol that shall be needed to provide Video Conferencing solution between Kashipur Campus and Mussoorie

Campus.

Q143. (a) Write the output of the code given below:

p=5

def sum(q,r=2): global p p=r+q**2

print(p, end= ‘#’)

a=10

b=5 sum(a,b)

sum(r=5,q=1)

(b) The code given below inserts the following record in the table Student:

RollNo – integer Name – string Clas – integer Marks – integer

Note the following to establish connectivity between Python and MYSQL:

• Username is root

• Password is tiger

• The table exists in a MYSQL database named school.

• The details (RollNo, Name, Clas and Marks) are to be accepted from the user.

Q.144Write the following missing statements to complete the code: Statement 1 – to form the cursor object

Statement 2 – to execute the command that inserts the record in the table Student.

Statement 3- to add the record permanently in the database

import mysql.connector as mysql def sql_data():

con1=mysql.connect(host=”localhost”,user=”root”, 2+3
password=”tiger”, database=”school”)

mycursor= #Statement 1 rno=int(input(“Enter Roll Number :: “)) name=input(“Enter name :: “) clas=int(input(“Enter class ::

“)) marks=int(input(“Enter Marks :: “)) querry=”insert into student

values({},'{}’,{},{})”.format(rno,name,clas,marks)

#Statement 2

# Statement 3

print(“Data Added successfully”)

OR

(a) Predict the output of the code given below:

s=”welcome2cs”

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)

(b) The code given below reads the following record from the table named student and displays only those records who have

marks greater than 75:

RollNo – integer Name – string Clas – integer Marks – integer

Note the following to establish connectivity between Python and MYSQL:

• Username is root

• Password is tiger

• The table exists in a MYSQL database named school.


Write the following missing statements to complete the code: Statement 1 – to form the cursor object

Statement 2 – to execute the query that extracts records of those students whose marks are greater than 75.

Statement 3- to read the complete result of the query (records whose

marks are greater than 75) into the object named data, from the table student in the database.

import mysql.connector as mysql def sql_data():

con1=mysql.connect(host=”localhost”,user=”root”, password=”tiger”, database=”school”)

mycursor= #Statement 1 print(“Students with marks greater than 75 are :

“)

#Statement 2

data= #Statement 3 for i in data:

print(i) print()

Q145. What is the advantage of using a csv file for permanent storage?

Q146 Write a Program in Python that defines and calls the following user defined functions:

(i) ADD() – To accept and add data of an employee to a CSV file ‘record.csv’. Each record consists of a list with field elements

as empid, name and mobile to store employee id, employee name and employee salary respectively.

(ii) COUNTR() – To count the number of records present in the CSV file named ‘record.csv’.

OR

Give any one point of difference between a binary file and a csv file. Write a Program in Python that defines and calls the

following user defined functions:

(i) add() – To accept and add data of an employee to a CSV file ‘furdata.csv’. Each record consists of a list with field elements

as fid, fname and fprice to store furniture id, furniture name and furniture price respectively.

(ii) search()- To display the records of the furniture whose price is more than 10000. 5
Class 12 Computer Science Sample Question Paper 2023: SECTION – E
Q147. Navdeep creates a table RESULT with a set of records to maintain the marks secured by students in Sem 1, Sem2,

Sem3 and their division. After creation of the table, he has entered data of 7 students in the table. 1+1+2

ROLL_NO SNAME SEM1 SEM2 SEM3 DIVISION

101 KARAN 366 410 402 I

102 NAMAN 300 350 325 I

103 ISHA 400 410 415 I

104 RENU 350 357 415 I

105 ARPIT 100 75 178 IV

106 SABINA 100 205 217 II

107 NEELAM 470 450 471 I

Based on the data given above answer the following questions:

Q.148(i) Identify the most appropriate column, which can be considered as Primary key.

Q149(ii) If two columns are added and 2 rows are deleted from the table result, what will be the new degree and cardinality

of the above table?

Q150(iii) Write the statements to:

a. Insert the following record into the table

Roll No- 108, Name- Aadit, Sem1- 470, Sem2-444, Sem3- 475, Div – I.

b. Increase the SEM2 marks of the students by 3% whose name begins with ‘N’.

OR (Option for part iii only)

(iii) Write the statements to:

a. Delete the record of students securing IV division.


b. Add a column REMARKS in the table with datatype as

varchar with 50 characters

Q151. Aman is a Python programmer. He has written a code and created a binary file record.dat with employeeid, ename

and salary. The file contains 10 records.

He now has to update a record based on the employee id entered by the user and update the salary. The updated record is

then to be written in the file temp.dat. The records which are not to be updated also have to be written to the file temp.dat.

If the employee id is not found, an appropriate message should to be displayed.

As a Python expert, help him to complete the following code based on the requirement given above:

import #Statement 1

def update_data(): rec={}

fin=open(“record.dat”,”rb”)

fout=open(” “) #Statement 2 found=False

eid=int(input(“Enter employee id to update their

salary :: “)) while True:

try:

rec= #Statement 3 if rec[“Employee id”]==eid:

found=True

rec[“Salary”]=int(input(“Enter new salary

:: “))

pickle. #Statement 4

else:

pickle.dump(rec,fout) except:

break

if found==True:

print(“The salary of employee id “,eid,” has been updated.”)

else:

print(“No employee with such id is not found”) fin.close()

fout.close()
Q.152(i) Which module should be imported in the program? (Statement 1)

Q153(ii) Write the correct statement required to open a temporary file named temp.dat. (Statement 2)

Q.154(iii) Which statement should Aman fill in Statement 3 to read the

data from the binary file, record.dat and in Statement 4 to write the updated data in the file, temp.dat?

You might also like