Students can Download Tamil Nadu 12th Computer Science Model Question Paper 1 English Medium Pdf, Tamil Nadu 12th Computer Science Model Question Papers helps you to revise the complete Tamilnadu State Board New Syllabus, helps students complete homework assignments and to score high marks in board exams.

## TN State Board 12th Computer Sceince Model Question Paper 1 English Medium

General Instructions:

1. The question paper comprises of four parts.
2. You are to attempt all the parts. An internal choice of questions is provided wherever applicable.
3. All questions of Part I, II, III and IV are to be attempted separately.
4. Question numbers 1 to 15 in Part I are Multiple Choice Questions of one mark each.
These are to be answered by choosing the most suitable answer from the given four alternatives and writing the option code and the corresponding answer
5. Question numbers 16 to 24 in Part II are two-mark questions. These are to be answered in about one or two sentences.
6. Question numbers 25 to 33 in Part III are three-mark questions. These are to be answered in about three to five short sentences.
7. Question numbers 34 to 38 in Part IV are five-mark questions. These are to be answered in detail Draw diagrams wherever necessary.

Time: 3 Hours
Maximum Marks: 70

PART – 1

Choose the correct answer. Answer all the questions: [15 × 1 = 15]

Question 1.
The duration for which a variable is alive is ………………..
(a) Scale
(b) Life time
(c) Static
(d) Function
(b) Life time Question 2.
………………. describes the lower bound of an algorithm.
(a) Big Ω
(b) Big Θ
(c) Big O
(d) Big ⊗
(a) Big Ω

Question 3.
How many types of operators are there?
(a) 2
(b) 3
(c) 4
(d) 5
(d) 5 Question 4.
The keys in python, dictionary is specified by ……………..
(a) =
(b) ;
(c) +
(d) :
(d) :

Question 5.
…………….. is used to access an element in a list.
(a) Element
(b) i
(c) Index
(d) Tuple
(c) Index

Question 6.
The command to delete a table is ………………..
(a) Drop
(b) Delete
(c) Delete all
(d) Alter table
(a) Drop Question 7.
‘skipinitialspace’ is used for removing ……………….. after delimiter.
(a) White spaces
(b) Double quotes
(c) Comma
(d) Colon
(a) White spaces

Question 8.
List literals are written using ………………
(a) [ ]
(b) ( )
(c) { }
(d) <>
(a) [ ]

Question 9.
What does ……………… name ………………. contains?
(a) C++ file name
(b) Main ( ) name
(c) Python file name
(d) OS module name
(c) Python file name Question 10.
Which of the following clause avoid the duplicates?
(a) Distinct
(b) Remove
(c) Where
(d) Group by
(a) Distinct

Question 11.
Which function returns the smallest value of the selected columns?
(a) Min ( )
(b) Minimum ( )
(c) Small ( )
(d) Least ( )
(a) Min ( )

Question 12.
Which is a python package used for 2D graphics?
(a) Matplotlib.pyplot
(b) Matplotlib.pip
(c) Matplotlib.numpy
(d) Matplotlib.plt
(a) Matplotlib.pyplot Question 13.
Skipping of first row heading in CSV file is given by ………………
(a) Skip
(b) Next
(c) Forward
(d) More
(b) Next

Question 14.
Which mode is used when dealing with non-text files like images or exe files?
(a) Text
(b) Word
(c) Binary
(d) Exe
(c) Binary Question 15.
In python _ del _ ( ) method is used as …………….
(a) Delete
(b) Drop
(c) Truncate
(d) Destructor
(d) Destructor

PART – II

Answer any six questions. Question No. 21 is compulsory. [6 × 2 = 12]

Question 16.
Who is an Algorist?

1. A person skilled in the design of algorithms are called as Algorist.
2. An algorithmic artist.

Question 17.
What is a repeating operator?
The multiplication operator (*) is used to display a string in multiple number of times. Question 18.
Write note on dictionary comprehensions?
In Python, comprehension is another way of creating dictionary. The following is the syntax of creating such dictionary.
Syntax
Dict = { expression for variable in sequence [if condition] }

Question 19.
What is the output of the following snippet?
T=1
while T:
print(True)
break
(a) False
(b) True
(c) 0
(d) No output
(d) No output Question 20.
List the control structures in python?
There are three important control structures

1. Sequential
2. Alternative or Branching
3. Iterative or Looping

Question 21.
Pick the correct one to execute the given statement successfully, if_: print(x, ” is a leap year”)
(a) x % 2 = 0
(b) x % 4 = = 0
(c) x/4 = 0
(d) x % 4 = 0
(b) x % 4 = = 0

Question 22.
What are the 4 types of function arguments?

1. Required arguments
2. Keyword arguments
3. Default arguments
4. Variable-length arguments Question 23.
Find output:
C = 65
Print (chr (C))
Output:
A

Question 24.
Give the positive and negative index for list [10, 23, 41]
Positive: 0 1 2
Negative: -3 -2 -1

PART – III

Answer any six questions. Question No. 29 is compulsory. [6 × 3 = 18]

Question 25.
Write a python program to check smallest of 3 numbers?
num1 = int (input(“Enter first number : “))
num2 = int (input(“Enter second number : “))
num3 = int (input(“Enter third number : “))
if (num1 < num2) and (num1 < num3):
smallest=num1
elif (num2 < num1) and (num2 < num3):
smallest=num2
else:
smallest=num3
print(” The smallest number is”, smallest)

Output:
Enter first number : 12
Enter second number : 7
Enter third number : 15
The smallest number is 7 Question 26.
Write a note on count ( ) function? Question 27.
What are the advantages of user – defined functions?

1. Functions help us to divide a program into modules. This makes the code easier to manage.
2. It implements code reuse. Every time you need to execute a sequence of statements, all you need to do is to call the function.
3. Functions, allows us to change functionality easily, and different programmers can work on different functions.

Question 28.
Write note on min ( ), max ( ), sum ( ) functions? Question 29.
What is the use of append ( ) and extend ( ) functions in python?
In Python, append() function is used to add a single element and extend() function is used to add more than one element to an existing list.

Syntax: Question 30.
Define Nested list, give example for it?
In the below example, Mylist contains another list as an element. This type of list is known as “Nested List”.
Nested list is a list containing another list as an element.
Example: Mylist = [ “Welcome”, 3.14, 10, [2, 4, 6] ]

Question 31.
Define list. How will you represent rational numbers with list?
List is constructed by placing expressions within square brackets separated by commas. Such an expression is called a list literal. List can store multiple values. Each value can be of any type and can even be another list. Example for List is [10, 20].

Representing Rational Numbers Using List:
You can now represent a rational number as a pair of two integers in pseudo code: a numerator and a denominator
rational(n, d):
return [n, d]
numer(x):
return x
denom(x):
return x[l] Question 32.
Define memoization?
Memoization or memoisation is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.

Question 33.
Mention any 6 keywords?

1. False
2. None
3. True
4. And
5. As
6. Assert

PART – IV

Answer all the following questions. [5 × 5 = 25]

Question 34 (a).
Explain the pseudo code to do Binary search?

• If the search element is equal to the middle element of the array i.e., the middle value = number of elements in array/2, then return the index of the middle element.
• If not, then compare the middle element with the search value.
• If the search element is greater than the number in the middle index, then select the elements to the right side of the middle index, and go to Step-1.
• If the search element is less than the number in the middle index, then select the elements to the left side of the middle index, and start with Step-1.

(II) When a match is found, display success message with the index of the element matched.

(III) If no match is found for all comparisons, then display unsuccessful message.

[OR]

(b) Give the pseudo code for insertion sort?
Step 1 – If it is the first element, it is already sorted.
Step 2 – Pick next element.
Step 3 – Compare with all elements in the sorted sub-list.
Step 4 – Shift all the elements in the sorted sub-list that is greater than the value to be sorted
Step 5 – Insert the value
Step 6 – Repeat until list is sorted Question 35 (a).
Explain input function with example?
input( ) function:
In Python, input( ) function is used to accept data as input at run time. The syntax for input( ) function is,
Variable = input (“prompt string ’’)

Where, prompt string in the syntax is a statement or message to the user, to know what input can be given. If a prompt string is used, it is displayed on the monitor; the user can provide expected data from the input device. The input( ) takes whatever is typed from the keyboard and stores the entered data in the given variable. If prompt string is not given in input( ) no message is displayed on the screen, thus, the user will not know what is to be typed as input.

Example: input( ) with prompt string
>>> city=input (“Enter Your City: ”)
>>> print (“I am from”, city)

Example: input( ) without prompt string
>>> city=input( )
Rajarajan
>>> print (“I am from”, city)
I am from Rajarajan

Note that in example-2, the input( ) is not having any prompt string, thus the user will not know what is to be typed as input. If the user inputs irrelevant data as given in the above example, then the output will be unexpected. So, to make your program more interactive, provide prompt string with input( ).

The input ( ) accepts all data as string or characters but not as numbers. If a numerical value is entered, the input values should be explicitly converted into numeric data type.

The int ( ) function is used to convert string data as integer data explicitly. We will learn about more such functions in later chapters.

Example:
x = int (input(“Enter Number 1: ”))
y = int (input(“Enter Number 2: ”))
print (“The sum = ”, x+y)
Output:
Enter Number 1 : 34
Enter Number 2 : 56
The sum = 90

Example: Alternate method for the above program
x,y=int (input(“Enter Number 1 :”)),int(input(“Enter Number 2:”))
print (“X = “,x,” Y = “,y)
Output:
Enter Number 1:30
Enter Number 2:50
X = 30 Y = 50

[OR]

(b) Explain various types of Relationships in dBMS?
Following are the types of relationships used in a database.

1. One-to-One Relationship
2. One-to-Many Relationship
3. Many-to-One Relationship
4. Many-to-Many Relationship

1. One-to-One Relationship
In One-to-One Relationship, one entity is related with only one other entity. One row in a table is linked with only one row in another table and vice versa.
For example: A student can have only one exam number 2. One-to-Many Relationship
In One-to-Many relationship, one entity is related to many other entities.
One row in a table A is linked to many rows in a table B, but one row in a table B is linked to only one row in table A.
For example: One Department has many staff members. 3. Many-to-One Relationship
In Many-to-One Relationship, many entities can be related with only one in the other entity. For example: A number of staff members working in one Department.
Multiple rows in staff members table is related with only one row in Department table. 4. Many-to-Many Relationship
A many-to-many relationship occurs when multiple records in a table are associated with multiple records in another table.

Example 1: Customers and Product
Customers can purchase various products and Products can be purchased by many customers.

Example 2: Students and Courses A student can register for many Courses and a Course may include many students.

Example 3: Books and Student.
Many Books in a Library are issued to many students.  Question 36 (a).
Write a menu driven program that keeps record of books available in school library?
class Library:
def init (self):
self.bookname=” ”
self.author=””

def getdata(self):
self.bookname = input(“Enter Name of the Book: “)
self.author = input(“Enter Author of the Book: “)

def display(self):
print(“Name of the Book: “,self.bookname)
print(“Author of the Book: “,self.author)
print(“\n”)

book=[ ] #empty list
ch = ‘y’

while(ch==’y’):
print(” 1. Add New Book \n 2.Display Books”)
resp = int(input(“Enter your choice : “))

if(resp==1):
L=Library( )
L.getdata( )
book.append(L)

elif(resp=2):
for x in book:
x.display( )

else:
print(“Invalid input….”)
ch = input(“Do you want continue….”)

Output:

2. Display Books Enter your choice : 1

Enter Name of the Book: Programming in C++
Enter Author of the Book: K. Kannan
Do you want continue….y

2. Display Books Enter your choice : 1

Enter Name of the Book: Learn Python
Enter Author of the Book: V.G.Ramakrishnan
Do you want continue….y

2. Display Books

Enter Name of the Book: Advanced Python
Enter Author of the Book: Dr. Vidhya
Do you want continue….y

2. Display Books

Enter Name of the Book: Working with OpenOffice
Enter Author of the Book: N.V.Gowrisankar
Do you want continue….y

2. Display Books

Enter Name of the Book: Data Structure
Enter Author of the Book: K.Lenin
Do you want continue….y

2. Display Books

Enter Name of the Book: An Introduction to Database System
Enter Author of the Book: R.Sreenivasan
Do you want continue….y

2. Display Books

Name of the Book: Programming in C++
Author of the Book: K. Kannan
Name of the Book: Learn Python
Author of the Book: V.G.Ramakrishnan
Name of the Book: Advanced Python
Author of the Book: Dr. Vidhya
Name of the Book: Working with OpenOffice
Author of the Book: N.V.Gowrisankar
Name of the Book: Data Structure
Author of the Book: K.Lenin
Name of the Book: An Introduction to Database System
Author of the Book: R.Sreenivasan
Do you want continue….n

[OR]

(b) Write a program to accept a string and print the number of upper case, vowels, consonants and spaces in the giving string?
class String:
def _init_(self):
self.uppercase=0
self.lowercase=0
self.vowels=0
self.consonants=0
self.spaces=0
self.string=””

def getstr(self):
self.string=str(input(“Enter a String: “))

def countupper(self):
for ch in self.string:
if (ch.isupper()):
self.uppercase+=1

def count_lower(self):
for ch in self.string:
if (ch.islower()):
self.lowercase+= 1

def count_vowels(self):
for ch in self.string:
if (ch in (‘A’, ‘a’, ‘e’, ‘E’, ‘i’, T, ’o’, ‘O’, T, ‘L’)):
self.vowels+=1

def countconsonants(self):
for ch in self.string:
if (ch not in (‘A’, ’a’, ‘e’, ‘E’, ‘i’, T, ‘o’, ‘O’, T, ’L’)):
self.consonants+= 1

def countspace(self):
for ch in self.string:
if (ch=””):
self.spaces+=1

def execute(self):
self.count_upper( )
self.count_lower( )
self. count_vowels( )
self.count_consonants( )
self.count_space( )

def display(self):
print(“The given string contains…”)
print(“%d Uppercase letters”%self.uppercase)
print(“%d Lowercase letters”%self.lowercase)
print(“%d Vowels”%self. vowels)
print(“%d Consonants”%self.consonants)
print(“%d Spaces”%self.spaces)
S = String( )
S.getstr( )
S.execute( )
S.display( )

Output:
Enter a String: Welcome To Learn Computer Science
The given string contains…
5 Uppercase letters
24 Lowercase letters
13 Vowels
20 Consonants
4 Spaces Question 37(a).
Explain python getopt module?
The getopt module of Python helps you to parse (split) command-line options and arguments. This module provides two functions to enable command-line argument parsing.
getopt.getopt method
This method parses command-line options and parameter list. Following is the syntax for this method –
<opts> ,<args>=getopt.getopt (argv, options, [long options])
Here is the detail of the parameters –

argv – This is the argument list of values to be parsed (splited). In our program the complete command will be passed as a list.
options – This is string of option letters that the Python program recognize as, for input or for output, with options (like ‘i’ or ‘o’) that followed by a colon (:). Here colon is used to denote the mode.

longoptions – This parameter is passed with a list of strings. Argument of Long options should be followed by an equal sign (‘=’). In our program the C++ file name will be passed as string and ‘i’ also will be passed along with to indicate it as the input file.

getopt( ) method returns value consisting of two elements. Each of these values are stored separately in two different list (arrays) opts and args. Opts contains list of splitted strings like mode, path and args contains any string if at all not splitted because of wrong path or mode. args will be an empty array if there is no error in splitting strings by getopt( ).

For example The Python code which is going to execute the C++ file p4 in command line will have the getopt() method like the following one.
opts, args = getopt.getopt (argv, “i:”,[‘ifile=’]) In our examples since the entire command line commands are parsed and no leftover argument, the second argument args will be empty [ ]. If args is displayed using print( ) command it displays the output as [ ].
>>>print(args)
[ ]

[OR]

(b) Write a sql code using where clause to display the different grades scored by male students from student table?
The WHERE clause is used to extract only those records that fulfill a specified condition. In this example we are going to display the different grades scored by male students from “student table” import sqlite3
cursor = connection.cursor( )
cursor.execute(” SELECT DISTINCT (Grade) FROM student where gender=’M”‘)
result = cursor.fetchall( )
print(*result,sep=”\n”)
OUTPUT
(‘B’,)
(‘A’,)
(C’,)
(D’,) Question 38 (a).
Write a program that accept data using python input ( ) command and write it in the Table called person?
In this example we are going to accept data using Python input() command during runtime and then going to write in the Table called “Person”

Example:
# code for executing query using input data import sqlite3
# creates a database in RAM
cur =con.cursor( )
cur.execute(“DROP Table person”)
cur.execute(“create table person (name, age, id)”)
print(“Enter 5 students names:”)
who =[input( ) for i in range(5)]
print(“Enter their ages respectively:”)
age =[int(input()) for i in range(5)]
print(“Enter their ids respectively:”)
p_id =[int(input())for i in range(5)]
n =len(who)
for i in range(n):
# This is the q-mark style:
cur.execute(“insert into person values (?, ?, ?)”, (who[i], age[i], p_id[i]))
# And this is the named style: cur.execute(“select * from person”)
# Fetches all entries from table
print(“Displaying All the Records From Person Table”)
print (*cur.fetchall( ), sep-\n’)

Output:
Enter 5 students names:
RAM
KEERTHANA
KRISHNA
HARISH
GIRISH

Enter their ages respectively:
28
12
21

Enter their ids respectively:
1
2
3
4
5

Displaying All the Records From Person Table
(‘RAM’, 28, 1)
(’KEERTHANA’, 12, 2)
(’KRISHNA1, 21,3)
(‘HARISH’, 18,4)
(‘GIRISH’, 16, 5)

You can even add records to the already existing table like “Student” Using the above coding with appropriate modification in the Field Name. To do so you should comment the create table statement

[OR]

(b) Write a CSV file with a line terminator?
A Line Terminator is a string used to terminate lines produced by writer. The default value is \r or \n. We can write csv file with a line terminator in Python by registering new dialects using csv.register_dialect( ) class of csv module.
For Example
import csv
Data = [[‘Fruit’, ‘Quantity’], [‘Apple’, ‘5’], [‘Banana’, ‘7’], [‘Mango’, ‘8’]]
csv.register_dialect(‘myDialect’, delimiter = ‘|’, lineterminator = ‘\n’)
with open(‘c:\\pyprg\\chl3\\line.csv’, ‘w’) as f:
writer = csv.writer(f, dialect=‘myDialect’)
writer.writerows(Data)
f.close( )
When we open the line.csv file, we get following output with spacing between lines: In the above code, the new dialect “myDialect uses the delimiter=‘|’ where a | (pipe) is considered as column separator. The line terminator=‘\r\n\r\n’ separates each row and display the data after every two lines.