Class 12 Computer Science Sample Paper With Solutions Set A

Sample Papers for Class 12

Please refer to Class 12 Computer Science Sample Paper With Solutions Set A provided below. The Sample Papers for Class 12 Computer Science have been prepared based on the latest pattern issued by CBSE. Students should practice these guess papers for class 12 Computer Science to gain more practice and get better marks in examinations. The Sample Papers for Computer Science Standard 12 will help you to understand the type of questions which can be asked in upcoming examinations.



Section – I

Select the most appropriate option out of the options given for each question. Attempt any 15 questions from question no. 1 to 21.
1. Which of the following is not a valid identifier name in Python? Justify reason for it not being a valid name.
(a) 5 Total
(b) _Radius
(c) pie
(d)While
Answer: a) 5 Total
Reason : An identifier cannot start with a digit.

2. Find the output –
>>>A = [17, 24, 15, 30]
>>>A.insert( 2, 33)
>>>print ( A [-4])
Answer: 24

3. Name the Python Library modules which need to be imported to invoke the following functions:
(i) ceil () (ii) randrange ()
Answer: (i) math (ii) random (½ mark for each module)

4. Which of the following are valid operator in Python:
(i) */
(ii) is
(iii) ^
(iv) like
Answer: Valid operators : (ii) is (iii) ^ (½ mark for each operator)
5. Which of the following statements will create a tuple ?
(a) Tp1 = (“a”, “b”)
(b) Tp1= (3) * 3
(c) Tp1[2] = (“a”, “b”)
(d) None of these
Answer:(a) Tp1 = (“a”, “b”)

6. What will be the result of the following code?
>>>d1 = {“abc” : 5, “def” : 6, “ghi” : 7} >>>print (d1[0])
(a) abc
(b) 5
(c) {“abc”:5}
(d) Error
Answer: D

7. Find the output of the following:
>>>S = 1, (2,3,4), 5, (6,7) >>> len(S)
Answer: 4

8. Which of the following are Keywords in Python ?
(i) break
(ii) check
(iii) range
(iv) while
Answer: (i) break (iv) while (½ mark for each option)

9. __________ is a specific condition in a network when more data packets are coming to network device than they can handle and process at a time.
Answer:Network Congestion

10. Ravi received a mail from IRS department on clicking “Click –Here”, he was taken to a site designed to imitate an official looking website, such as IRS.gov. He uploaded some important information on it.
Identify and explain the cybercrime being discussed in the above scenario.
Answer: It is an example of phishing

11. Which command is used to change the number of columns in a table? 
Answer:  ALTER

12. Which keyword is used to select rows containing column that match a wildcard pattern?
Answer: LIKE

13. The name of the current working directory can be determined using ______method.
Answer: etcwd()

14. Differentiate between Degree and Cardinality. 
Answer: Degree – it is the total number of columns in the table.
Cardinality – it is the total number of tuples/Rows in the table

15. Give one example of each – Guided media and Unguided media 
Answer: Guided – Twisted pair, Coaxial Cable, Optical Fiber (any one) Unguided – Radio waves, Satellite, Micro Waves (any one)

16. Which of the following statement create a dictionary?
a) d = { }
b) d = {“john”:40, “peter”:45}
c) d = (40 : “john”, 45 : “peter”}
d) d = All of the mentioned above
Answer: D

17 Find the output of the following:
>>>Name = “Python Examination”
>>>print (Name [ : 8 : -1])
Answer: noitanima

18 All aggregate functions except ___________ ignore null values in their input collection.
(a) Count (attribute)
(b) Count (*)
(c) Avg ()
(d) Sum ()
Answer: B

19 Write the expand form of Wi-Max. 1
Answer: Wi-Max – Worldwide Interoperability for Microwave Access

20. Group functions can be applied to any numeric values, some text types and DATE values. (True/False)
Answer: True

21. _______________ is a network device that connects dissimilar networks. 
Answer: Gateway

Section – II

Both the Case study based questions are compulsory. Attempt any sub parts from each question. Each question carries 1 mark.

22. A department is considering to maintain their worker data using SQL to store the data. As a database administer, Karan has decided that :
Name of the database – Department
Name of the table – WORKER
The attributes of WORKER are as follows:
WORKER_ID – character of size 3
FIRST_NAME – character of size 10
LAST_NAME– character of size 10
SALARY – numeric
JOINING_DATE – Date
DEPARTMENT – character of size

(a) Write a query to create the given table WORKER. 
(b) Identify the attribute best suitable to be declared as a primary key. 
(c) Karan wants to increase the size of the 
(d) Karan wants to remove all the data from table WORKER from the database Department. Which command will he use from the following:
i) DELETE FROM WORKER;
ii) DROP TABLE WORKER;
iii) DROP DATABASE Department;
iv) DELETE * FROM WORKER;
e) Write a query to display the Structure of the table WORKER, i.e. name of the attribute and their respective data types.
Answer: a) Create table WORKER(WORKER_ID varchar(3), FIRST_NAME
varchar(10), LAST_NAME varchar(10), SALARY integer, JOINING_DATE Date, DEPARTMENT varchar(10));
b) WORKER_ID
c) alter table worker modify FIRST_NAME varchar(20);
d) DELETE FROM WORKER;
e) Desc WORKER / Describe WORKER;

23. Ashok Kumar of class 12 is writing a program to create a CSV file “empdata.csv” with empid, name and mobile no and search empid and display the record. He has written the following code. As a programmer, help him to successfully execute the given task.
import _____  fields=[’empid’,’name’,’mobile_no’]
rows=[[‘101′,’Rohit’,’8982345659′],[‘102′,’Shaurya’,’8974564589′],
[‘103′,’Deep’,’8753695421′],[‘104′,’Prerna’,’9889984567′],
[‘105′,’Lakshya’,’7698459876′]]
filename=”empdata.csv” 
with open(filename,’w’,newline=”) as f:
csv_w=csv.writer(f,delimiter=’,’)
csv_w.___________ #Line2
csv_w.___________ #Line3
with open(filename,’r’) as f:
csv_r=______________(f,delimiter=’,’) #Line4
ans=’y’
while ans==’y’:
found=False
emplid=(input(“Enter employee id to search=”))
for row in csv_r:
if len(row)!=0:
if _____==emplid: #Line5
print(“Name : “,row[1])
print(“Mobile No : “,row[2])
found=True
1*4=4
Page 5 of 10
break
if not found:
print(“Employee id not found”)
ans=input(“Do you want to search more? (y)”)
(a) Name the module he should import in Line 1. 1
(b) Write a code to write the fields (column heading) once from fields list in Line2.
(c) Write a code to write the rows all at once from rows list in Line3. 1
(d) Fill in the blank in Line4 to read the data from a csv file. 1
(e) Fill in the blank to match the employee id entered by the user with the empid of record from a file in Line5.
Answer: a) csv
b) writerow(fields)
c) writerows(rows)
d) csv.reader
e) row[0]

PART – B

Section – I

24. Evaluate the following expressions:
a) 12*(3%4)//2+6
b) not 12 > 6 and 7 < 17 or not 12 < 4
Answer: a) 24
b) True

25. Define and explain all parts of a URL of a website. i.e. https://www.google.co.in. It has various parts.
OR
Define cookies and hacking.
Answer: URL stands for Uniform Resource Locator and it is the complete address of a website or web server, e.g.https://www.google.co.in- name of the
protocol : https, Web service : www, name of the server: google, DNS Name : co, Name of the country site belongs : in (india)
OR
Cookies: .Cookies are messages that a web server transmits to a web browser so that the web server can keep track of the user’s activity on a specific website. Cookies are saved in the form of text files in the client computer.
Hacking: It is a process of accessing a computer system or network without knowing the access authorization credential of that system.
Hacking can be illegal or ethical depending on the intention of the hacker.

26. Expand the following terms:
(a) IPR
(b) SIM
(c) IMAP
(d) HTTP
Answer: a) IPR – Intellectual Property Rights
b) SIM – Subscriber’s Identity Module
c) IMAP – Internet Message Access Protocol
d) HTTP – Hyper text transfer Protocol

27. What is the difference between a Local Scope and Global Scope ? Also, give a suitable Python code to illustrate both.
OR
Define different types of formal arguments in Python, with example.
Answer: A local scope is variable defined within a function. Such variables are said to have local scope. With example A global variable is a variable defined in the ;main’ program (_main_section). Such variables are said to have global scope. With example
OR
Python supports three types of formal arguments :
1) Positional arguments (Required arguments) – When the function call statement must match the number and order of arguments as defined in
the function definition. Eg. def check (x, y, z) :
2) Default arguments – A parameter having default value in the function header is known as default parameter. Eg. def interest(P, T, R=0.10) :
3) Keyword (or named) arguments- The named arguments with assigned value being passed in the function call statement. Eg. interest (P=1000,
R=10.0, T = 5)

28. Observe the following Python code very carefully and rewrite it after removing all syntactical errors with each correction underlined.
DEF result_even( ):
x = input(“Enter a number”)
if (x % 2 = 0) :
print (“You entered an even number”)
else:
print(“Number is odd”)
even ( )
Answer: def result_even( ):
x = int(input(“Enter a number”))
if (x % 2 == 0) :
print (“You entered an even number”)
else:
print(“Number is odd”)
result_even( )

29. What possible output(s) are expected to be displayed on screen at the time of execution of the program from the following code? Also specify the minimum values that can be assigned to each of the variables BEGIN and LAST.
import random
VALUES = [10, 20, 30, 40, 50, 60, 70, 80]
BEGIN = random.randint (1, 3)
LAST = random.randint(2, 4)
for I in range (BEGIN, LAST+1):
print (VALUES[I], end = “-“)
(i) 30-40-50-
(ii) 10-20-30-40-
(iii) 30-40-50-60-
(iv) 30-40-50-60-70-
Answer: OUTPUT – (i) 30-40-50-
Minimum value of BEGIN: 1
Minimum value of LAST: 2

30. What is the difference between Primary Key and Foreign Key? Explain with Example.
Answer: Primary Key: A primary key is used to ensure data in the specific column is unique. It is a column cannot have NULL values. It is either an existing table column or a column that is specifically generated by the database according to a defined sequence.
Example: Refer the figure – STUD_NO, as well as STUD_PHONE both, are candidate keys for relation STUDENT but STUD_NO can be chosen as the primary key (only one out of many candidate keys).
Foreign Key:
A foreign key is a column or group of columns in a relational database table that provides a link between data in two tables. It is a column (orcolumns) that references a column (most often the primary key) of another table.
Example: Refer the figure –
STUD_NO in STUDENT_COURSE is a foreign key to STUD_NO in  STUDENT relation.

31. What is the use of commit and rollback command in MySql. 
Answer: Commit : My Sql Connection.commit() method sends a COMMIT statement to the My Sql server, committing the current transaction.Rollback: My Sql Connection .rollback reverts the changes made by the current transaction.

32. Differentiate between WHERE and HAVING clause.
Answer: WHERE clause is used to select particular rows that satisfy a condition whereas HAVING clause is used in connection with the aggregate function, GROUP BY clause.
For ex. – select * from student where marks > 75; This statement shall display the records for all the students who have scored more than 75 marks.
On the contrary, the statement – select * from student group by stream having marks > 75; shall display the records of all the students grouped together on the basis of stream but only for those students who have scored marks more than 75

33. Find and write the output of the following Python code:
def makenew(mystr):
newstr = ” “
count = 0
for i in mystr:
if count%2 !=0:
newstr = newstr+str(count)
else:
if i.islower():
newstr = newstr+i.upper()
else:
newstr = newstr+i
count +=1
newstr = newstr+mystr[:1]
print(“The new string is :”, newstr)
makenew(“sTUdeNT”)
Answer: The new string is : S1U3E5Ts
(1/2 mark for each change i.e. S 1 3 E 5 s )

SECTION – II

34 Write a function bubble_sort (Ar, n) in python, Which accepts a list Ar of numbers and n is a numeric value by which all elements of the list are sorted by Bubble sort Method.
Answer: 
def bubble_sort(Ar, n):
print (“Original list:”, Ar)
for i in range(n-1):
for j in range(n-i-1):
if Ar[j] > Ar[j+1]:
Ar[j], Ar[j+1] = Ar[j+1], Ar[j]
print (“List after sorting :”, Ar)
Note: Using of any correct code giving the same result is also accepted.

35. Write a function in python to count the number lines in a text file ‘Country.txt’ which is starting with an alphabet ‘W’ or ‘H’. If the file contents are as follows:
Whose woods these are I think I know.
His house is in the village though;He will not see me stopping here To watch his woods fill up with snow.
The output of the function should be:
W or w : 1
H or h : 2
OR
Write a user defined function to display the total number of words present in the file.
A text file “Quotes.Txt” has the following data written in it:Living a life you can be proud of doing your best Spending your time with people and activities that are important to you Standing up for things that are right even when it’s hard Becoming the best version of you.
The countwords() function should display the output as:
Total number of words : 40
Answer: def count_W_H():
f = open (“Country.txt”, “r”)
W,H = 0,0
r = f.read()
for x in r:
if x[0] == “W” or x[0] == “w”:
W=W+1
elif x[0] == “H” or x[0] == “h”:
H=H+1
f.close()
print (“W or w :”, W)
print (“H or h :”, H)
OR
def countwords():
s = open(“Quotes.txt”,”r”)
f = s.read()
z = f.split ()
count = 0
for I in z:
count = count + 1
print (“Total number of words:”, count)
Note: Using of any correct code giving the same result is also accepted

36. Write the output of the SQL queries (i) to (iii) based on the table: Employee

(i) Select sum(Salary) from Employee where Gender = ‘F’ and Dept = ‘Sales’;
(ii) Select Max(DOB), Min(DOB) from Employee;
(iii) Select Gender, Count(*) from Employee group by Gender;
Answer: OUTPUT:-
(i) 43000
(ii) Max (DOB) Min(DOB)
08-10-1995 05-071993
(iii) Gender Count(*)
        F          3
        M         3

37. Write a function Add Customer(Customer) in Python to add a new Customer information NAME into the List of CS tack and display the information.
OR
Write a function Delete Customer() to delete a Customer information from a list of CS tack. The function delete the name of customer from the stack.
Answer: def Add Customer(Customer):
CStake.append(Customer)
If len(CS tack)==0:
print (“Empty Stack”)
else:
print (C Stack)
OR
def DeleteCustomer():
if (CStack ==[]):
print(“There is no Customer!”)
else:
print(“Record deleted:”,CStack.pop())

SECTION – III
38. Intelligent Hub India is a knowledge community aimed to uplift the standard of skills and knowledge in the society. It is planning to setup its training centres in multiple towns and villages of India with its head offices in the nearest cities. They have created a model of their network with a city, a town and 3 villages as given.
As a network consultant, you have to suggest the best network related solution for their issues/problems raised in (i) to (v) keeping in mind the distance between various locations and given parameters.

Note:
* In Villages, there are community centres, in which one room has been given as training center to this organization to install computers.
* The organization has got financial support from the government and top IT companies.
1. Suggest the most appropriate location of the SERVER in the YHUB (out of the 4 locations), to get the best and effective connectivity. Justify your answer.
2. Suggest the best wired medium and draw the cable layout (location to location) to efficiently connect various locations within the YHUB.
3. Which hardware device will you suggest to connect all the computers within each location of YHUB?
4. Which server/protocol will be most helpful to conduct live interaction of Experts from Head office and people at YHUB locations?
5. Suggest a device/software and its placement that would provide data security for the entire network of the YHUB.
Answer: (i) YTOWN
Justification:-Since it has the maximum number of computers.
It is closet to all other locatios. 80-20 Network rule.
(ii) Optical Fiber
Layout:
(iii) Switch or Hub
(iv) Video conferencing or VoIP or any other correct service/protocol
(v) Firewall- Placed with the Server at YHUB.

39. Write SQL commands for the following queries (i) to (v) based on the relation
Trainer and Course given below:

(i) Display the Trainer Name, City & Salary in descending order of their Hiredate.
(ii) To display the TNAME and CITY of Trainer who joined the Institute in the month of December 2001.
(iii) To display TNAME, HIREDATE, CNAME, STARTDATE from tables TRAINER and COURSE of all those courses whose FEES is less than or equal to 10000.
(iv) To display number of Trainers from each city.
(v) To display the Trainer ID and Name of the trainer who are not belongs to ‘Mumbai’ and ‘DELHI’
Answer: (i) SELECT TNAME, CITY, SALARY FROM TRAINER ORDER BY HIREDATE;
(ii) SELECT TNAME, CITY FROM TRAINER WHERE HIREDATE BETWEEN ‘2001-12-01’ AND ‘2001-12-31’;
(iii) SELECT TNAME, HIREDATE, CNAME, STARTDATE FROM TRAINER, COURSE WHERE TRAINER.TID=COURSE.TID AND FEES<=10000;
(iv) SELECT CITY, COUNT(*) FROM TRAINER GROUP BY CITY;
(v) SELECT TID, TNAME, FROM TRAINER WHERE CITY NOT IN(‘DELHI’,‘MUMBAI’);

40. Given a binary file “emp.dat” has structure (Emp_id, Emp_name, Emp_Salary). Write a function in Python countsal() in Python that would read contents of the file “emp.dat” and display the details of those employee whose salary is greater than 20000.
OR
A binary file “Stu.dat” has structure (rollno, name, marks).
(i) Write a function in Python add_record() to input data for a record and add to Stu.dat.
(ii) Write a function in python Search_record() to search a record from binary file “Stu.dat” on the basis of roll number.
Answer:(Using of any correct code giving the same result is also accepted)
import pickle
def countsal():
f = open (“emp.dat”, “rb”)
n = 0
try:
while True:
rec = pickle.load(f)
if rec[2] > 20000:
print(rec[0], rec[1], rec[2], sep=”\t”)
num = num + 1
except:
f.close()
OR
import pickle
def add_record():
fobj = open(“Stu.dat”,”ab”)
rollno =int(input(“Roll no:”))
name = int(input(“Name:”))
marks = int(input(“Marks:”))
data = [rollno, name, marks]
pickle.dump(data,fobj)
fobj.close()
def Search_record():
f = open(“Stu.dat”, “rb”)
stu_rec = pickle.load(f)
found = 0
rno = int(input(“Enter the roll number to search:”))
try:
for R in stu_rec:
if R[0] == rno:
print (“Successful Search:, R[1], “Found!”)
found = 1
break
except:
if found == 0:
print (“Sorry, record not found:”)
f.close()