 # Class 12 Computer Science 083 Sample Papers with Solution – SQP 1

Thanks for visiting on my websites. Here I am trying to provide 20 sample question papers with solutions for Computer Science Code 083 class 12. It will help you in your preparation. Go with every question carefully. Try to solve it before checking the answer to that question.

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

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

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. 

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

print(reverse(1234))

```

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. 

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

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? 

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

21. (b) Write the output of the following code. 
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. 

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 

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

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

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;

SELECT COUNT(discount) FROM sales;

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

Relation: Dept

What will be the output of the following statement?

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

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

Table Name: Sportsclub

• (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’;

(i)

(ii)

(iii)

(iv)

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

def displaywords( ):
fin = open(“data.txt”, “r”)
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.

def countvowel( ):
fin = open(“info.txt”, “r”)
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

Table: Booking

(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.

(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]

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.

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.

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:

Distance Between the various blocks:

• (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

(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)

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)

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.

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.

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.

(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

fin = open(“data.dat”, “rb”)
try:
dic = { }
while True :
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

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.

(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
data = [[‘India’, ‘Delhi’,130],[‘USA’,’Washington DC’,50],[Japan,Tokyo,2]]
f = open(‘country.csv’,’w’, newline=””)
csvwriter = csv.writer(f)
_______________ #Statement 2
f.close()
f = open(‘country.csv’,’r’)
for x in _____:               #Statement 4
if int(x) > 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

(a)  import csv

(b)  csvwriter.writerows(data)

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

Complete code:

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