Higher Secondary Second Year Cs Answer Key
Higher Secondary Second Year Cs Answer Key
Q. ANSWER MARKS
NO
1 c) Definition 1
2 a) constructor 1
3 b) LEGB 1
4 c) Half-interval search 1
5 b) Ternary 1
6 a) for 1
7 d) return 1
8 a) Positive or negative numbers 1
9 a) eceicS retupmoC 1
10 d) . (dot) 1
11 b) Chen 1
12 b) SELECT 1
13 a) Modification 1
14 b) OS module 1
15 b) Distinct 1
2 MARKS
Q. ANSWER MARKS
NO
Pair:
16 Pair is a compound structure which is made up of list or 1
Tuple.
Any way of bundling two values together into one can be 1
considered as a pair.
Example: lst := [10, 20]
The process of arranging the list items in ascending or 1
17 descending order is called sorting.
Example: Bubble Sort, Selection Sort, Insertion Sort. 1
Output:
18 5 10 15 2
Slice is a substring of a main string.
19 A substring can be taken from the original string by using
[ ] operator and index or subscript values. 2
Thus, [ ] is also known as slicing operator.
Using slice operator, you have to slice one or more
substrings from a main string.
General format of slice operation: str [start: end]
20 Destructor is also a special method gets executed automatically
when an object exit from the scope.
In python, _del_ () method is used as destructor. 2
It is just opposite to constructor.
General format : def __del__(self):
<statements>
21 Command Description Component
Insert Insert data into table DML 1
1
Create To create a tables in the Database DDL 1
22 Syntax: cd: < absolute path>
“cd” command used to change directory and absolute path 1
refers to the complete path where python is installed.
Example : “cd c:\program files\openoffice4\Program”
1
23 Matplotlib can be installed using pip software.
Pip is a management software for installing python 1
packages.
Importing Matplotlib using the command:
import matplotlib.pyplot as plt 1
Matplotlib can be imported in the workspace.
24 Output:
False 1
welcome 1
3 MARKS
Q. ANSWER MARKS
NO
25 Impure Function:
The variables used inside the function may cause side
effects though the functions which are not passed with any
arguments. 2
In such cases the function is called impure function.
Ex:
let randomnumber :=
a := random()
if a>10 then
return: a 1
else
return: 10
26 Global Scope:
A variable which is declared outside of all the functions in
a program is known as global variable.
Global variable can be accessed inside or outside of all the 2
functions in a program.
Example:
Entire Program Output of the Program
1. a:=10 a:=10
2. Disp(): 7
Disp():
3. a:=7 1
a:=7
4. print a print a 10
5. Disp()
6. print a Disp():
print a
2
There are various compound operators in Python like +=,
-=, *=, /=, %=, **= and //= are also available.
ceil() floor()
Returns the smallest integer Returns the largest integer
28 greater than or equal to x. less than or equal to x. 3
Ex:print(math.ceil(23.6)) Ex:print(math.floor(23.6))
Output : 24 Output:23
Syntax:
remove() List.remove(element) 1
29 pop() List.pop(index of an element) 1
clear() List.clear() 1
CARTESIAN PRODUCT (Symbol: X)
Cross product is a way of combining two relations. The
resulting relation contains, both relations being combined. 2
30 A X B means A times B, where the relation A and B have
different attributes.
Ex:
A=3, B=2 means AXB=3X2=6.
1
31 reader( ) method DictReader class
The reader method is DictReader works by reading
designed to take each line of the first line of the CSV and
the file and make a list of all using each comma separated
columns value in this line as a dictionary
key.
Using this method one can DictReader is a class of csv
read data from csv files of module is used to read a CSV 3
different format like quotes file into a dictionary.
(‘ ’),(pip (│), and comma(,).
csv.reader works with It creates an object which maps
list\tuple. data to a dictionary.
Syntax: Syntax: csv.DictReader work
csv.reader(fileobject,delimiter with dictionary
,fmtparams)
32 fetchone() fetchmany()
The fetch one () method returns The fetchmany() method
the next row of a query result returns the next number of
set or none in case there is no rows (n) of the result set.
row left. 3
Using while loop and fetchone() Displaying specified number
method we can display all the of records is done by using
records from a table. fetchmany().
33 Output:
[1,4,9,16,25] 3
5 MARKS
Q. ANSWER MARKS
NO
34 Pure Function:
A) Pure functions are functions which will give exact result
when the same arguments are passed.
3
Pure function does not cause any side effects to its output.
The return value of the pure functions solely depends on
its arguments passed.
They do not modify the arguments which are passed to
them.
If we call pure functions with same set of arguments, we
will always get the same result.
Example:
let square x:=
return: x*x
5
Impure Function:
Impure functions never assure you that the function will
behave the same every time it’s called.
Impure function causes side effects to its output.
The return value of the impure functions does not solely
depend on its arguments passed.
They may modify the arguments which are passed.
If we call impure functions with same set of arguments, we
might get the different return values.
Example:
let randomnumber:=
a:=random( )
if a>10 then
return: a
else
return: 10
34 Hierarchical Model:
B) Hierarchical model was developed by IBM.
In Hierarchical model, data is represented as a simple tree
like structure form. This model represents a one-to-many
relationship. i.e., parent-child relationship.
One child can have only one parent but one parent can
have many children. This model is mainly used in IBM
Main Frame.
2. Relational Model:
The Relational Database model was first proposed by
E.F.Codd in 1970.
Nowadays, it is the most widespread data model used for
database applications around the world.
The basic structure of data in relational model is tables
(relations). 5
4
All the information’s related to a particular type is stored
in rows of that table.
A relation key is an attribute which uniquely identifies a
particular tuple.
3. Network Model:
Network database model is an extended form of
hierarchical data model.
The difference between hierarchical and Network data
model is: In hierarchical model, a child record has only
one parent node.
In a Network model, a child may have many parent nodes.
It represents the data in many-to-many relationships.
This model is easier and faster to access the data.
5
5. Object Model:
Object model stores the data in the form of objects,
attributes and methods, classes and Inheritance.
This model handles more complex applications, such as
Geographic information System (GIS), scientific
experiments, engineering design and manufacturing.
It is used in file Management System.
It represents real world objects, attributes and behaviours.
Example:
where,
Shape is the class.
Circle, Rectangle and Triangle are objects of class Shape.
radius, length, breadth, base and height are attributes.
get_area() and get_perimeter() are the methods.
35 Operators in Python:
A) In computer programming languages operators are special
symbols which represent computations, conditional matching
etc.
i. The value of an operator used is called operands.
ii. Operators are categorized as Arithmetic, Relational,
Logical, Assignment, Conditional etc.
iii. Value and variables when used with operator are known 5
as operands.
Arithmetic operators:
1. An arithmetic operator is a mathematical operator that
takes two operands and performs a calculation on them.
2. They are used for simple arithmetic.
Relational or Comparative operators:
1. A Relational operator is also called as Comparative
operator which checks the relationship between two
operands.
2. If the relation is true, it returns True; otherwise it returns
False.
Logical operators :
6
a. In python, Logical operators are used to perform logical
operations on the given relational expressions.
b. There are three logical operators they are and, or and not.
Assignment operators:
a. In Python, = is a simple assignment operator to assign
values to variable.
b. There are various compound operators in Python like +=,
-=, *=, /=, %=, **= and //= are also available.
Conditional operator or Ternary operator :
Ternary operator is also known as conditional operator
that evaluate something based on a condition being true
or false.
Syntax: Variable Name = [on_true] if [Test expression] else
[on_false ]
35 Constraint:
B) Constraint is a condition applicable on a field or set of fields
Types of Constraint:
1. Unique Constraint 2.Primary Key Constraint 3.Default
Constraint 4. Check Constraint 5. Table constraint
1.Unique Constraint:
This constraint ensures that no two rows have the same
value in the specified columns.
For example UNIQUE constraint applied on Admno of
student table ensures that no two students have the same
admission number and the constraint can be used as:
CREATE TABLE Student (
Admno integer NOT NULL UNIQUE, → Unique constraint
Name char (20) NOT NULL, Gender char (1),Age integer,
Place char (10));
3.DEFAULT Constraint :
The DEFAULT constraint is used to assign a default value
for the field.
7
When no value is given for the specified field having
DEFAULT constraint, automatically the default value will
be assigned to the field.
Example:
CREATE TABLE Student (
Admno integer NOT NULL PRIMARY KEY, Name char(20)NOT
NULL, Gender char(1), Age integer DEFAULT = “17”, → Default
Constraint Place char(10) );
In the above example the “Age” field is assigned a default
value of 17, therefore when no value is entered in age by
the user, it automatically assigns 17 to Age.
4. Check Constraint :
This constraint helps to set a limit value placed for a field.
When we define a check constraint on a single column, it
allows only the restricted values on that field.
Example:
CREATE TABLE Student (
Admno integer NOT NULL PRIMARY KEY Name char(20)NOT
NULL, Gender char(1), Age integer (CHECK<=19), → Check
Constraint Place char(10));
5.TABLE CONSTRAINT :
When the constraint is applied to a group of fields of the
table, it is known as Table constraint.
The table constraint is normally given at the end of the
table definition.
Let us take a new table namely Student1 with the following
fields Admno, First name, Last name, Gender, Age, Place:
CREATE TABLE Student 1 (
Admno integer NOT NULL, Firstname char(20), Lastname
char(20), Gender char(1), Age integer, Place char(10),
PRIMARY KEY (Firstname, Lastname) → Table constraint );
In the above example, the two fields, First name and Last
name are defined as Primary key which is a Table
constraint.
36 Syntax:
A) while <condition>:
statements block 1
[else:
statements block2]
Example:
Program to print numbers from 10 to 15 using while loop.
i=10
while (i<=15):
print (i,end='\t'
i=i+1
Output: 10 11 12 13 14 15
36 Python File Modes:
B) 1) 'r' Open a file for reading (default).
2) 'w' Open a file for writing. Creates new file if it does not
exist or truncates the file if it exists.
3) 'x' Open a file for exclusive creation. If the file already 5
exists, the operation fails.
4) 't' Open in text mode (default).
5) 'a' Open for appending at the end of the file without
truncating it. Creates a new file if it does not exist.
6) 'b' Open in binary mode.
7) '+' Open a file for updating (reading and writing).
37 Recursion Function:
A) When a function calls itself is known as recursion.
Recursion works like loop but sometimes it makes more
sense to use recursion than loop.
You can convert any loop to recursion. A recursive
function calls itself.
Imagine a process would iterate indefinitely if not stopped
by some condition! Such a process is known as infinite 5
iteration.
The condition that is applied in any recursive function is
known as base condition.
A base condition is must in every recursive function
otherwise it will continue to execute like an infinite loop.
9
This module provides access to some variables used by the
interpreter and to functions that interact strongly with the
interpreter.
sys. argv:
sys.argv is the list of command-line arguments passed to
the Python program.
argv contains all the items that come via the command-
line input, it's basically a list holding the command line
arguments of the program.
To use sys.argv, import sys should be used. The first
argument, sys. argv [0] contains the name of the python
program
(example pali.py) and sys. argv [1] is the next argument
passed to the program (here it is the C++ file).
Python's OS Module :
The OS module in Python provides a way of using
operating system dependent functionality. 5
The functions that the OS module allows you to interface
with the Windows operating system where Python is
running on.
os.system(): Execute the C++ compiling command (a
string contains Unix, C command which also supports
C++ command) in the shell (Here it is Command Window).
For Example to compile C++ program g++ compiler
should be invoked.
Command:
os.system(‘g++’ + <variable_name1> + ‘-<mode>’ +
<variable_name2>)
Syntax:
For example:
opts, args = getopt.getopt (argv, "i:",['ifile='])
where opts contains [('-i', 'c:\\pyprg\\p4')]
-i :- option nothing but mode should be followed by : (colon)
'c:\\pyprg\\p4' value nothing but the absolute path of C++ file.
>>>print(args)
[]
38 {1,2,3,4,5,6,7,8}
A) {4,5}
{1,2,3}
{6,7,8}
{1,2,3,6,7,8}
1. COUNT()
The SQL COUNT() function returns the number of rows
in a table satisfying the criteria specified in the WHERE
clause.
COUNT() returns 0 if there were no matching rows.
Example:
import sqlite3
connection = sqlite3.connect("Academy.db")
cursor = connection.cursor()
11
cursor.execute("SELECT COUNT(*) FROM student ")
result = cursor.fetchall()
print(result)
Output: [(7,)]
2. AVG()
The following SQL statement in the python program finds
the average mark of all students.
Example:
import sqlite3
connection = sqlite3.connect("Academy.db")
cursor = connection.cursor()
cursor.execute("SELECT AVG(AVERAGE) FROM student ")
result = cursor.fetchall()
print(result)
Output
[(84.65714285714286,)]
3. SUM():
The following SQL statement in the python program finds
the sum of all average in the Average field of “Student
table”.
Example:
import sqlite3
connection = sqlite3.connect("Academy.db")
cursor = connection.cursor()
cursor.execute("SELECT SUM(AVERAGE) FROM student ")
result = cursor.fetchall()
print(result)
Output: [(592.6,)]
4.MAX()
❖ The MAX() function returns the largest value of the selected
column.
5.MIN()
❖ The MIN() function returns the smallest value of the selected
column.
Prepared By
12