Anjeev Singh Academy

Class 12 Computer Science 083 Sample Papers with Solution – SQP 7

Sample Question Paper – 7 with Answer Key

General Instructions:

  • This question paper contains five sections, Sections A to E.
  • All questions are compulsory.
  • Section A have 18 questions carrying 01 mark each.
  • Section B has 07 Very Short Answer type questions carrying 02 marks each.
  • Section C has 05 Short Answer type questions carrying 03 marks each.
  • Section D has 03 Long Answer type questions carrying 05 marks each.
  • Section E has 02 questions carrying 04 marks each. One internal choice is given in Q34 against part c only.
  • All programming questions are to be answered using Python Language only.

SECTION A

1State True or False “Python has a set of keywords that can also be used to declare variables”  
Answer: – False.
Explanation:– A keyword cannot be use to declare a variable
1
2Which of the following is not a valid python operator?
a) %                       b) in                c) #                         d) **  
Answer: – c) #
Explanation:-  # is use for single line comment in python, Triple quote is use for multiline comments.
1
3What will be the output of the following python dictionary operation?  
data = {‘A’:2000, ‘B’:2500, ‘C’:3000, ‘A’:4000} print(data)

a) {‘A’:2000, ‘B’:2500, ‘C’:3000, ‘A’:4000}      
b) {‘A’:2000, ‘B’:2500, ‘C’:3000}
c) {‘A’:4000, ‘B’:2500, ‘C’:3000}                     
d) It will generate an error.  

Answer: – c) {‘A’:4000, ‘B’:2500, ‘C’:3000}
Explanation: Dictionary does not allow duplicate key, so when you entered the duplicate key , it will update the key with the last value.

1
4print(True or not True and False) Choose one option from the following that will be the correct output after executing the above python expression.
a) False                    b) True                c) or                 d) not
Answer: –  b) True
=> True or not True and False  
=> True or False and False 
=> True or False 
=> True                   #Final Answer
1
5Select the correct output of the following python code:  

str=”My program is program for you”
t = str.partition(“program”)
print(t)

a) (‘My ‘, ‘program’, ‘ is ‘, ‘program’, ‘ for you’)           
b)    (‘My ‘, ‘program’, ‘ is program for you’)
c)    (‘My ‘, ‘ is program for you’)                                  
d)     (‘My ‘, ‘ is ‘, ‘ for you’)  

Answer: –  b) (‘My ‘, ‘program’, ‘ is program for you’)

Explanation: string.partition() function partition the string into the three values tuple. It partition on the first occurrence of given value.
1
6Which of the file opening mode will open the file for reading and writing in binary mode.
a) rb                          b) rb+                  c) wb                 d) a+  

Answer: –  b) rb+   (read & write binary)
1
7Which of the following statements is True?
a) There can be only one Foreign Key in a table.    
b)   There can be only one Unique key is a table
c)    There can be only one Primary Key in a Table    
d)    A table must have a Primary Key.  

Answer: –  c) There can be only one Primary Key in a Table  
1
8Which of the following is not part of a DDL query?
a) DROP                        b) MODIFY            c) DISTINCT         d) ADD  

Answer: –  c) DISTINCT  

Explanation: ADD, MODIFY, CHANGE, ALTER AND DROP are clauses used with ALTER TABLE command. ALTER TABLE command is a DDL COMMAND.
1
9Which of the following operations on a string will generate an error?
a) “PYTHON”*2                            b)    “PYTHON” + “10”
c)     “PYTHON” + 10                        d)    “PYTHON” + “PYTHON”  

Answer: –  c) “PYTHON” + 10
1
10   ______ Keyword is used to obtain unique values in a SELECT query.
a) UNIQUE                b)   DISTINCT              c)   SET            d)   HAVING  

Answer: –  c) DISTINCT
1
11  Which of the following python statement will bring the read pointer to 10th character from the end of a file containing 100 characters, opened for reading in binary mode.
a) File.seek(10,0)      
b)   File.seek(-10,2)    
c) File.seek(-10,1)    
d) File.seek(10,2)  

Answer: –  b) File.seek(-10, 2)  

Explanation:
seek(offset, mode) is used to move the file pointer (cursor) to the specified position as per mode. By default the value of mode is 0 i.e. beginning of file.

It can be 1 – for current location, and 2 for end of the file.

For example
=> File.seek(10 ) or File.seek(10, 0) -:- Move the file pointer at the 10th position (i.e. 10th character) from the beginning of the file.
=> File.seek(10 , 1 ) -:- Move the file pointer 10 position forward from the current position of the file pointer.
=> File.seek(-10 , 1 ) -:- Move the file pointer 10 position backward from the current position of the file pointer.  
=> File.seek(-10 , 2 )  -:- Move the file pointer 10 position backward from the end of the file.
1
12  Which statement in MySql will display all the tables in a database?
a) SELECT * FROM TABLES;    
b)  USE TABLES;  
c)  DESCRIBE TABLES;   
d)  SHOW TABLES;  

Answer: –  d) SHOW TABLES;
1
13Which of the following is used to receive emails over the Internet?
a) SMTP             b) POP             c) PPP            d) VoIP  

Answer: –  a) SMTP (Simple Mail Transfer Protocol)
1
14What will be the output of the following python expression?
print(2**3**2)
a) 64            b) 256             c) 512            d) 32

Answer: c) 512
1
15  Which of the following is a valid sql statement?
a) ALTER TABLE student SET rollno INT(5);
b) UPDATE TABLE student MODIFY age = age + 10;
c) DROP FROM TABLE student;
d) DELETE FROM student;

Answer: –  d) DELETE FROM student;
1
16Which of the following is not valid cursor function while performing database operations using python. Here Mycur is the cursor object?
a) Mycur.fetch()              b)   Mycur.fetchone()     
c)   Mycur.fetchmany(n)     d)  Mycur.fetchall()

Answer: –  a) Mycur.fetch()
1

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): A variable declared as global inside a function is visible with changes made to it outside the function. Reasoning (A): All variables declared outside are not visible inside a function till they are re-declared with global keyword.

Answer: –  c) A is True but R is false
1
18  Assertion (A): A binary file in python is used to store collection objects like lists and dictionaries that can be later retrieved in their original form using pickle module. Reasoning (A): A binary files are just like normal text files and can be read using a text editor like notepad.

Answer: –  c) A is True but R is False
1

SECTION B [2 Marks]

19. Sameer has written a python function to compute the reverse of a number. He has however committed a few errors in his code. Rewrite the code after removing errors and also underline the corrections made. [2]

define reverse(num):
    rev  = 0
    While num > 0: 
          rem == num %10
          rev = rev*10 + rem 
          num = num//10
      return rev

print(reverse(1234))

Answer: –

def reverse(num):
      rev  = 0
     while num > 0:
     rem = num %10
rev = rev*10 + rem
num = num //10
     return rev
print(reverse(1234))

20. Mention two differences between a Hub and a switch in networking. [2]

Answer: –  HUB vs SWITCH

HUB: – (i) It broadcast the messages to all computers in networks.
(ii) It shares the bandwidth.

SWITCH: – (i) It sends the message separately to the computer.
(ii) It segments the network.
(iii) It does not share the bandwidth, so all computers in the network can use the full speed of the internet.

OR

Mention one advantage and one disadvantage of Star Topology.

Answer: –  STAR TOPOLOGY

Advantages: (i) All computers are connected with central computer. (ii) Information are available and shared by Central Computer. (iii) Damage of node does not impact on network.

Disadvantages: – (i) Expansion is not easy. (ii) Long cable length is required. (iii) If server is not working, then it stop the network.

21. (a) What will be the output of the following string operation? [1]

str=”PYTHON@LANGUAGE”
print(str[2:12:2])

Answer: –  TO@NU

21. (b) Write the output of the following code. [1]
data = [1,2,4,5]
for x in data:
        x = x + 10
      print(data)

Answer: – [1, 2, 4, 5]

22. Mention two differences between a PRIMARY KEY and a UNIQUE KEY. [2]

Answer: –  PRIMARY KEY vs  UNIQUE KEY

PRIMARY KEY

  • The value of the primary key is always UNIQUE.
  • The primary Key does not allow a NULL value.
  • Only one Primary Key is allowed in a table.

UNIQUE KEY

  • The value of unique key is always UNIQUE.
  • Unique Key is allow NULL value.
  • More than one UNIQUE key is allowed in a table.

23. (a) Expand the following abbreviations:   (i) URL   (ii) TCP [1]

Answer: – (i) URL – Uniform Resource Locator  
  (ii) TCP – Transmission Control Protocol

23. (b) What is the use of VoIP? [1]

Answer: – VoIP stands for Voice Over Internet Protocol. It allows voice communication as data on the internet.

24. Predict the output of the following python code:
def foo(s1,s2):
l1=[]
l2=[]
for x in s1:
     l1.append(x)
for x in s2:
    l2.append(x)
return l1,l2
a, b = foo(“FUN”,’DAY’)
print(a,b)

Answer: – [‘F’, ‘U’, ‘N’] [‘D’, ‘A’, ‘Y’]

OR

Predict the output of the following python code:
data = [2,4,2,1,2,1,3,3,4,4]
d = {}
for x in data:
if x in d:
d[x] = d[x]+1
else:
d[x]=1
print(d)

Answer: – {2 : 3, 4 : 3, 1 : 2, 3 : 2}

Question 25 :

A MySQL table, sales have 10 rows. The following queries were executed on the sales table.

SELECT COUNT(*) FROM sales;

COUNT(*)
10

SELECT COUNT(discount) FROM sales;

COUNT(discount)
6

Write a statement to explain as to why there is a difference in both the counts.

Answer: – COUNT(*) count the number of rows in a table, while COUNT(discount) counts number of NON-NULL values in column discount.

OR

What is the difference between a Candidate Key and an Alternate Key.

Answer: – Candidate Key :- Attributes of columns, which have capability to become PRIMARY KEY, is known as Candidate Key.
Alternate Key: – Candidate Key, which is not selected as PRIMARY KEY, is known as Alternate Key.

SECTION – C [3 Marks]

Question 26: (1+2)

(a) Consider the following tables Emp and Dept:

Relation: Emp

empcodeenamedeptidSalary
1001TOM1010000
1002BOB118000
1003SID109000
1004JAY129000
1005JIM1110000

Relation: Dept

deptiddname
10Physics
11Chemistry
12Biology

What will be the output of the following statement?

SELECT * FROM Emp NATURAL JOIN Dept
WHERE dname=’Physics’;

Answer:

   empcodeenamedeptidSalarydname
1001TOM1010000Physics
1003SID109000Physics

(b) : Write the output of the queries (i) to (iv) based on the table Sportsclub

Table Name: Sportsclub

playeridpnamesportscountryratingsalary
10001PELESOCCERBRAZILA50000
10002FEDERERTENNISSWEDENA20000
10003VIRATCRICKETINDIAA15000
10004SANIATENNISINDIAB5000
10005NEERAJATHLETICSINDIAA12000
10006BOLTATHLETICSJAMAICAA8000
10007PAULSNOOKERUSAB10000
  • (i) SELECT DISTINCT sports FROM Sportsclub;
  • (ii) SELECT sports, MAX(salary) FROM Sportsclub GROUP BY sports HAVING sports <> ‘SNOOKER’;
  • (iii) SELECT pname, sports, salary FROM Sportsclub WHERE country=’INDIA’ ORDER BY salary DESC;
  • (iv) SELECT SUM(salary) FROM Sportsclub WHERE rating=’B’;

Answer:

(i)

sports
SOCCER
TENNIS
CRICKET
ATHLETICS
SNOOKER

(ii)

sportsMAX(salary)
SOCCER50000
TENNIS20000
CRICKET15000
ATHLETICS12000

(iii)

playeridsportssalary
10003CRICKET15000
10005ATHLETICS12000
10004TENNIS5000

(iv)

SUM(salary)
15000

Question 27: (3)

A pre-existing text file data.txt has some words written in it. Write a python function displaywords() that will print all the words that are having length greater than 3.

Example: For the fie content:
A man always wants to strive higher in his life He wants to be perfect.

The output after executing displayword() will be:
Always wants strive higher life wants perfect

Answer: –

def displaywords( ):
      fin = open(“data.txt”, “r”)
      text = fin.read( )    
      for word in text.split( ):
             if len(word) > 3 :
                    print(word, end = ‘  ’)
      fin.close( )

OR

A pre-existing text file info.txt has some text written in it. Write a Python function countvowel() that reads the contents of the file and counts the occurrence of vowels(A,E,I,O,U) in the file.

Answer: –

def countvowel( ):
       fin = open(“info.txt”, “r”)
       text = fin.read( )
       count = 0
       for character in text:
              if character in ‘AEIOU’:
                      count += 1
      fin.close( )

Question 28: (3)

Based on the given set of tables write answers to the following questions:

Table: Flights

ticketnopassengersourcedestinationquantitypriceflightid
10001ARUNBANDEL2700010
10002ORAMBANKOL3750012
10003SUMITADELMUM1600015
10004ALIMUMKOL2560012
10005GAGANMUMDEL4500010

Table: Booking

flightidmodelcompany
10747Boeing
12320Airbus
15767Boeing

(a) Write a query to display the passenger, source, model and price for all bookings whose destination is KOL.
(b) Identify the column acting as foreign key and the table name where it is present in the given example.

Answer:

(a) SELECT passenger, source, model, price
FROM Flights, Booking
WHERE Flights.flightid = Booking.flightid AND destination = ‘KOL’ ;

(b) Foreign Key : flightid                  
Table name : flights

Question 29: (3)

Write a function modilst(L) that accepts a list of numbers as argument and increases the value of the elements by 10 if the elements are divisible by 5. Also write a proper call statement for the function.
For example:
If list L contains [3,5,10,12,15]
Then the modilist() should make the list L as [3,15,20,12,25]

Answer: –

def modilst(L):
      for i in len(L):
            if L[i] % 5 = = 0 :
                   L[i] = L[i] * 3

L = [3,5,10,12,15]

modilst(L)       #Function calling statement
print(L)

Question 30: (3)

A dictionary contains the names of some cities and their population in crore. Write a python function push(stack, data), that accepts an empty list, which is the stack and data, which is the dictionary and pushes the names of those countries onto the stack whose population is greater than 25 crores.
For example :
The data is having the contents {‘India’:140, ‘USA’:50, ‘Russia’:25, ‘Japan’:10} then the execution of the function push() should push India and USA on the stack.

Answer: –

stack = [ ]
def push( stack, data):
for key in data :
if data[key] > 25 :
stack.append( key )

data = {‘India’:140, ‘USA’:50, ‘Russia’:25, ‘Japan’:10}
push(stack, data)
print(stack)

OR

A list of numbers is used to populate the contents of a stack using a function push(stack, data) where stack is an empty list and data is the list of numbers. The function should push all the numbers that are even to the stack. Also write the function pop() that removes the top element of the stack on its each call.

Answer: –

data = [3, 6, 2, 9, 10, 16]
stack = [ ]
def push( stack, data):
for value in data :
if value % 2 = = 0:
stack.append(value)
def pop( ):
if stack = = [ ] : # if len(stack) == 0:
return “Stack empty”
else:
value = stack.pop( )
return value

SECTION – D (5 Marks)

Question 31: (5)

Magnolia Infotech wants to set up their computer network in the Bangalore based campus having four buildings. Each block has a number of computers that are required to be connected for ease of communication, resource sharing and data security. You are required to suggest the best answers to the questions i) to v) keeping in mind the building layout on the campus.

Number of Computers:

BlockNumber of computers
Development100
HR120
Admin200
Logistics110

Distance Between the various blocks:

BlockDistance
Development to HR50m
Development to Admin75m
Development to Logistics120m
HR to Admin110m
HR to Logistics50m
Admin to Logistics140m
  • (i) Suggest the most appropriate block to host the Server. Also justify your choice.
  • (ii) Suggest the device that should be placed in the Server building so that they can connect to Internet Service Provider to avail Internet Services.
  • (iii) Suggest the wired medium and draw the cable block-to-block layout to economically connect the various blocks.
  • (iv) Suggest the placement of Switches and Repeaters in the network with justification.
  • (v) Suggest the high-speed wired communication medium between Bangalore Campus and Mysore campus to establish a data network

Answer: –

(i) Admin

(ii) MODEM

(iii) Wired medium – Twisted Pair

Cable Layout – 1 [Economic Connection]

Cable Layout – 2 (Direct Connection with Server of two block)

(iv) Placement of Switch: –  Admin, Development, HR, and Logistics [ Because all have more than two computers]

Placement of Repeater:   Repeater is not required in Cable Layout-1

 In Cable Layout – 2, Repeater is required between ADMIN to HR, because the distance is more than 100 m

(v) Fiber Optics [ for high-speed wired connection]

Question 32: (2 + 3 = 5)

a) Write the output of the following code:

def change(m, n=10):
global x
x += m
n += x
m = n + x
print(m, n, x)
x=20
change(10)
change(20)

Answer: – Output is
70 40 30
110 60 50

OR

What will be the output of the following Python program?

str = “”
name = “9@Days”
for x in name:
if x in “aeiou”:
str += x.upper()
elif not x.isalnum():
str += “**”
elif x.isdigit():
pass
else:
str += x.lower()
print(str)

Answer: – Output is: 9**dAYS

b) Sumitra wants to write a program to connect to MySQL database using python and increase the age of all the students who are studying in class 11 by 2 years.
Since she had little understanding of the coding, she left a few blank spaces in her code. Now help her to complete the code by suggesting correct coding for statements 1, 2 and 3.

import _______ as myc # Statement 1
con = myc.connect(host=”locahost”, user=”root”, passwd=””, database=”mydb”)
mycursor = _______ # Statement 2
sql = “UPDATE student SET age = age + 2 WHERE class=’XI’ “
mycursor.execute(sql)
sql = “SELECT * FROM student”
mycursor=con.execute(sql)
result = _________ # Statement 3
for row in result:
print(row)

Statement 1: The required module to be imported
Statement 2: To initialize the cursor object.
Statement 3: To read all the rows from the cursor object.

Answer: –

Statement 1: mysql.connector
Statement 2: con.cursor( )
Statement 3: mycursor.fetchall( )

Question 33: (2 + 3 = 5)

A binary file data.dat needs to be created with the following data written it in the form of Dictionaries.

RollnoNameAge
1001TOM17
1002BOB16
1003KAY16

Write the following functions in python to accommodate the data and manipulate it.

(a) A function insert( ) that creates the data.dat file in your system and writes the three dictionaries.
(b) A function read( ) that reads the data from the binary file and displays the dictionaries whose age is 16.

Answer:

(a)

  import pickle
  def insert( ):
        dic = { }
        fout = open(“data.dat”, “wb”)
        for i in range(3):
                rollno = int(input(“Enter Roll Number : ” ))
                name = input(“Enter name : ”  )
                 age = int (input (“Enter Age : ”))
               dic[‘Rollno’] = rollno
                dic[‘Name’] = name
                dic[‘Age’]  = age
                pickle.dump( dic, fout)
         fout.close( )

(b)

 import pickle

 def read( ) :
       fin = open(“data.dat”, “rb”)
       try:
             dic = { }
             while True :        
                     dic = pickle.load(fin)
                     if dic[‘Age’] = = 16:
                             print( dic[‘Rollno’], dic[‘Name’], dic[‘Age’] )
       catch :
             fin.close( )

SECTION – E

Question 34: (1+1+2 = 4)

Tarun created the following table in MySQL to maintain stock for the items he has.

Table: Inventory

Productidpnamecompanystockpricerating
10001BiscuitParley100015C
10002ToffeeParley5005B
10003EclairsCadbury80010A
10004Cold DrinkCoca Cola50025NULL
1005BiscuitBritania50030NULL
1006ChocolateCadbury70050C

Based on the above table answer the following questions.
(a) Identify the primary key in the table with valid justification.
(b) What is the degree and cardinality of the given table?
(c) Write a query to increase the stock for all products whose company is Parley.
OR (only for part c)
(c) Write a query to delete all the rows from the table which are not having any rating.

Answer:

(a) Primary Key – Productid, because its value is unique for all rows/tuples in the table inventory.

(b) Degree [Number of Columns in a table ] = 6
Cardinality [ Number of rows/tuples in a table ] = 6  

Note: Don’t count the column header row in the cardinality.

(c) UPDATE Inventory
SET stock = stock + 20
WHERE company = ‘Parley’;

OR

DELETE FROM Inventory
WHERE rating IS NULL;

Question 35: (4)

Sudheer has written a program to read and write using a csv file. He has written the following code but failed to write completely, leaving some blanks. Help him to complete the program by writing the missing lines by following the questions a) to d)

_________   #Statement 1
headings = [‘Country’,’Capital’,’Population’]
data = [[‘India’, ‘Delhi’,130],[‘USA’,’Washington DC’,50],[Japan,Tokyo,2]]
f = open(‘country.csv’,’w’, newline=””)
csvwriter = csv.writer(f)
csvwriter.writerow(headings)
_______________ #Statement 2
f.close()
f = open(‘country.csv’,’r’)
csvreader = csv.reader(f)
head = __________ #Statement 3
print(head)
for x in _____:               #Statement 4
     if int(x[2]) > 50:
            print(x)

  • (a) Statement 1 – Write the python statement that will allow Sudheer work with csv files.
  • (b) Statement 2 – Write a python statement that will write the list containing the data available as a nested list in the csv file
  • (c) Statement 3 – Write a python statement to read the header row in to the head object.
  • (d) Statement 4 – Write the object that contains the data that has been read from the file

Answer: –

(a)  import csv

(b)  csvwriter.writerows(data)

(c)  csvreader.next ( )    # to read only one row, and move the file pointer to the next row.

(d)  csvreader

Complete code:

import csv                                   #Statement 1
headings = [‘Country’,’Capital’,’Population’]
data = [[‘India’, ‘Delhi’,130],[‘USA’,’Washington DC’,50],[Japan,Tokyo,2]]
f = open(‘country.csv’,’w’, newline=””)
csvwriter = csv.writer(f)
csvwriter.writerow(headings) csvwriter.writerows(data)            #Statement 2
f.close()

f = open(‘country.csv’,’r’)
csvreader = csv.reader(f)
head = csvreader.next ( )             #Statement 3
print(head)
for x in csvreader :                     #Statement 4
     if int(x[2]) > 50:
            print(x)

Sorry! You cannot copy content of this page. Please contact, in case you want this content.

Scroll to Top