0% found this document useful (0 votes)
136 views33 pages

PlusTwoCompSci MLM EM

This document contains a chapter on functions from a Plus Two Computer Science textbook. It provides 10 multiple choice questions to test understanding of functions, including definitions of subroutines, functions, parameters, arguments, and pure vs impure functions. It also includes chapters on data abstraction, scoping, algorithmic strategies, Python variables and operators, and control structures, each with additional multiple choice questions.

Uploaded by

rsgk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views33 pages

PlusTwoCompSci MLM EM

This document contains a chapter on functions from a Plus Two Computer Science textbook. It provides 10 multiple choice questions to test understanding of functions, including definitions of subroutines, functions, parameters, arguments, and pure vs impure functions. It also includes chapters on data abstraction, scoping, algorithmic strategies, Python variables and operators, and control structures, each with additional multiple choice questions.

Uploaded by

rsgk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

N.S.Hr.Sec.

School, Theni
Plus Two Computer Science
Chapter 1-Function

Choose the best answer

1. The small sections of code that are used to perform a particular task is called

(A) Subroutines (B) Files (C) Pseudo code (D) Modules

2. Which of the following is a unit of code that is often defined within a greater code structure?

(A) Subroutines (B) Function (C) Files (D) Modules

3. Which of the following is a distinct syntactic block?

(A) Subroutines (B) Function (C) Definition (D) Modules

4. The variables in a function definition are called as

(A) Subroutines (B) Function (C) Definition (D) Parameters

5. The values which are passed to a function definition are called

(A) Arguments (B) Subroutines (C) Function (D) Definition

6. Which of the following are mandatory to write the type annotations in the function definition?

(A) Curly braces (B) Parentheses (C) Square brackets (D) indentations

7. Which of the following defines what an object can do?

(A) Operating System (B) Compiler (C) Interface (D) Interpreter

8. Which of the following carries out the instructions defined in the interface?

(A) Operating System (B) Compiler (C) Implementation (D) Interpreter

9. The functions which will give exact result when same arguments are passed are called

(A) Impure functions (B) Partial Functions

(C) Dynamic Functions (D) Pure functions

10. The functions which cause side effects to the arguments passed are called

(A) impure function (B) Partial Functions

(C) Dynamic Functions (D) Pure functions

N.S.Hr.Sec.School, Theni Page 1


Chapter 2- Data Abstraction

1. Which of the following functions that build the abstract data type ?

(A) Constructors (B) Destructors (C) recursive (D)Nested

2. Which of the following functions that retrieve information from the data type?

(A) Constructors (B) Selectors (C) recursive (D)Nested

3. The data structure which is a mutable ordered sequence of elements is called

(A) Built in (B) List (C) Tuple (D) Derived data

4. A sequence of immutable objects is called

(A) Built in (B) List (C) Tuple (D) Derived data

5. The data type whose representation is known are called

(A) Built in datatype (B) Derived datatype

(C) Concrete datatype (D) Abstract datatype

6. The data type whose representation is unknown are called

(A) Built in datatype (B) Derived datatype

(C) Concrete datatype (D) Abstract datatype

7. Which of the following is a compound structure?

(A) Pair (B) Triplet (C) single (D) quadrat

8. Bundling two values together into one can be considered as

(A) Pair (B) Triplet (C) single (D) quadrat

9. Which of the following allow to name the various parts of a multi-item object?

(A) Tuples (B) Lists (C) Classes (D) quadrats

10. Which of the following is constructed by placing expressions within square brackets?

(A) Tuples (B) Lists (C) Classes (D) quadrats

Chapter 3- Scoping
Choose the best answer (1 Mark)
1. Which of the following refers to the visibility of variables in one part of a program to another
part of the same program.

(A) Scope (B) Memory (C) Address (D) Accessibility

N.S.Hr.Sec.School, Theni Page 2


2. The process of binding a variable name with an object is called

(A) Scope (B) Mapping (C) late binding (D) early binding

3. Which of the following is used in programming languages to map the variable and object?

(A) :: (B) := (C) = (D) ==

4. Containers for mapping names of variables to objects is called

(A) Scope (B) Mapping (C) Binding (D) Namespaces

5. Which scope refers to variables defined in current function?

(A) Local Scope (B) Global scope (C) Module scope (D) Function Scope

6. The process of subdividing a computer program into separate sub-programs is called

(A) Procedural Programming (B) Modular programming


(C)Event Driven Programming (D) Object oriented Programming

7. Which of the following security technique that regulates who cause resources in a computing
environment?

(A) Password (B)Authentication (C) Access control (D) Certification

8. Which of the following members of a class can be handled only from within the class?

(A) Public members (B)Protected members (C) Secured members (D) Private members

9. Which members are accessible from outside the class?

(A) Public members (B)Protected members (C) Secured members (D) Private members

10. The members that are accessible from within the class and are also available to its sub-
classes is called

(A) Public members (B)Protected members (C) Secured members (D) Private members

Chapter 4- Algorithmic Strategies


Choose the best answer: (1 Marks)

1 .The word comes from the name of a Persian mathematician Abu Ja’far Mohammed ibn-i Musa al
Khowarizmi is called?

(A) Flowchart (B) Flow (C) Algorithm (D) Syntax

2. From the following sorting algorithms which algorithm needs the minimum number of swaps?

(A) Bubble sort (B) Quick sort (C) Merge sort (D) Selection sort

N.S.Hr.Sec.School, Theni Page 3


3. Two main measures for the efficiency of an algorithm are

(A) Processor and memory (B) Complexity and capacity


(C) Time and space (D) Data and space

4. The complexity of linear search algorithm is

(A) O(n) (B) O(log n) (C) O(n2) (D) O(n log n)

5. From the following sorting algorithms which has the lowest worst case complexity?
(A) Bubble sort (B) Quick sort (C) Merge sort (D) Selection sort

6. Which of the following is not a stable sorting algorithm?


(A) Insertion sort (B) Selection sort (C) Bubble sort (D) Merge sort

7. Time complexity of bubble sort in best case is


(A) θ (n) (B) θ (nlogn) (C) θ (n2) (D) θ (n(logn) 2)

8. The Θ notation in asymptotic evaluation represents


(A) Base case (B) Average case (C) Worst case (D) NULL case

9. If a problem can be broken into sub problems which are reused several times, the problem
possesses which property?

(A) Overlapping sub problems (B) Optimal substructure (C) Memoization (D) Greedy

10. In dynamic programming, the technique of storing the previously calculated values is called ?

(A) Saving value property (B) Storing value property


(C) Memoization (D) Mapping
Chapter 5 -Python Variables and Operators

1.Who developed Python ?


A) Ritche B) Guido Van Rossum C) Bill Gates D) Sunder Pitchai

2. The Python prompt indicates that Interpreter is ready to accept instruction.


A) >>> B) <<< C) # D) <<

3. Which of the following shortcut is used to create new Python Program ?


A) Ctrl + C B) Ctrl + F C) Ctrl + B D) Ctrl + N

4. Which of the following character is used to give comments in Python Program ?


A) # B) & C) @ D) $

5. This symbol is used to print more than one item on a single line.
A) Semicolon(;) B) Dollar($) C) comma(,) D) Colon(:)

N.S.Hr.Sec.School, Theni Page 4


6. Which of the following is not a token ?
A) Interpreter B) Identifiers C) Keyword D) Operators

7.Which of the following is not a Keyword in Python ?


A) break B) while C) continue D) operators

8.Which operator is also called as Comparative operator?


A) Arithmetic B) Relational C) Logical D) Assignment

9.Which of the following is not Logical operator?


A) and B) or C) not D) Assignment

10. Which operator is also called as Conditional operator?


A) Ternary B) Relational C) Logical D) Assignment

Chapter 6- Control Structures


Choose the best answer 1 Marks
1.How many important control structures are there in Python?

A) 3 B) 4 C) 5 D) 6

2.elif can be considered to be abbreviation of


A) nested if B) if..else C) else if D) if..elif

3.What plays a vital role in Python programming?


A) Statements B) Control C) Structure D) Indentation

4.Which statement is generally used as a placeholder?


A) continue B) break C) pass D) goto

5.The condition in the if statement should be in the form of


A) Arithmetic or Relational expression B) Arithmetic or Logical expression
C) Relational or Logical expression D) Arithmetic

6.Which is the most comfortable loop?


A) do..while B) while C) for D) if..elif

7.What is the output of the following snippet?


i=1
while True:
if i%3 ==0: break
print(i,end='')
i +=1
A) 12 B) 123 C) 1234 D) 124

8.What is the output of the following snippet?


T=1
while T:
print(True)

N.S.Hr.Sec.School, Theni Page 5


break
A) False B) True C) 0 D) no output

9.Which amongst this is not a jump statement ?


A) for B) goto C) continue D) break

10. Which punctuation should be used in the blank?


if <condition>_
statements-block 1
else:
statements-block 2
A) ; B) : C) :: D) !

Chapter 7- Python Functions

1.A named blocks of code that are designed to do one specific job is called as

(a) Loop (b) Branching (c) Function (d) Block

2.A Function which calls itself is called as

(a) Built-in (b) Recursion (c) Lambda (d) return

3. Which function is called anonymous un-named function

(a) Lambda (b) Recursion (c) Function (d) define

4. Which of the following keyword is used to begin the function block?

(a) define (b) for (c) finally (d) def

5. Which of the following keyword is used to exit a function block?

(a) define (b) return (c) finally (d) def

6. While defining a function which of the following symbol is used.

(a) ; (semicolon) (b) . (dot) (c) : (colon) (d) $ (dollar)

7.In which arguments the correct positional order is passed to a function?


(a) Required (b) Keyword (c) Default (d) Variable-length

8.Read the following statement and choose the correct statement(s).


(I) In Python, you don’t have to mention the specific data types while defining function.
(II) Python keywords can be used as function name.
(a) I is correct and II is wrong (b) Both are correct
(c) I is wrong and II is correct (d) Both are wrong

9.Pick the correct one to execute the given statement successfully. if ____ : print(x, " is a leap year")

N.S.Hr.Sec.School, Theni Page 6


(a) x%2=0 (b) x%4==0 (c) x/4=0 (d) x%4=0

10. Which of the following keyword is used to define the function testpython(): ?

(a)define (b)Pass (c)def (d)while

Chapter 8- Strings and String Manipulation

1.Which of the following is the output of the following python code?


str1="TamilNadu" print(str1[::-1])
(a) Tamilnadu (b) Tmlau (c) udanlimaT d) udaNlimaT

2.What will be the output of the following code? str1 = "Chennai Schools" str1[7] = "-"
(a) Chennai-Schools (b) Chenna-School (c) Type error (D) Chennai

3.Which of the following operator is used for concatenation?

(a) + (b) & (c) * d) =

4.Defining strings within triple quotes allows creating:


(a) Single line Strings (b) Multiline Strings (c) Double line Strings (d) Multiple Strings

5.Strings in python:

(a) Changeable (b) Mutable (c) Immutable (d) flexible

6.Which of the following is the slicing operator?

(a) { } (b) [ ] (c) < > (d) ( )

7.What is stride?
(a) index value of slide operation (b) first argument of slice operation
(c) second argument of slice operation (d) third argument of slice operation

8.Which of the following formatting character is used to print exponential notation in upper case?

(a) %e (b) %E (c) %g (d) %n

9.Which of the following is used as placeholders or replacement fields which get replaced along with
format( ) function?

(a) { } (b) < > (c) ++ (d) ^^

10. The subscript of a string may be:

(a) Positive (b) Negative (c) Both (a) and (b) (d) Either (a) or (b)

N.S.Hr.Sec.School, Theni Page 7


Chapter 9 - Lists, Tuples, Sets And Dictionary

1.Pick odd one in connection with collection data type

(a) List (b) Tuple (c) Dictionary (d) Loop

2.Let list1=[2,4,6,8,10], then print(List1[-2]) will result in

(a) 10 (b) 8 (c) 4 (d) 6

3.Which of the following function is used to count the number of elements in a list?

(a) count() (b) find() (c)len() (d) index()

4.If List=[10,20,30,40,50] then List[2]=35 will result

(a) [35,10,20,30,40,50] (b) [10,20,30,40,50,35] (c) [10,20,35,40,50] (d) [10,35,30,40,50]

5.If List=[17,23,41,10] then List.append(32) will result

(a) [32,17,23,41,10] (b) [17,23,41,10,32] (c) [10,17,23,32,41] (d) [41,32,23,17,10]

6.Which of the following Python function can be used to add more than one element within an
existing list?
(a) append() (b) append_more() (c)extend() (d) more()

7. What will be the result of the following Python code? S=[x**2 for x in range(5)] print(S)

(a) [0,1,2,4,5] (b) [0,1,4,9,16] (c) [0,1,4,9,16,25] (d) [1,4,9,16,25]

8. What is the use of type() function in python? x


a) To create a Tuple b) To know the type of an element in tuple.
c) To know the data type of python object. d) To create a list.

9.Which of the following statement is not correct?


a) A list is mutable b) A tuple is immutable.
c) The append() function is used to add an element.
d) The extend() function is used in tuple to add elements in a list.
10.Let setA={3,6,9}, setB={1,3,9}. What will be the result of the following snippet? print(setA|setB)
(a) {3,6,9,1,3,9} (b) {3,9} (c) {1} (d) {1,3,6,9}

11.Which of the following set operation includes all the elements that are in two sets but not the one
that are common to two sets?

(a) Symmetric difference (b) Difference (c) Intersection (d) Union

12.The keys in Python, dictionary is specified by

(a) = (b) ; (c)+ (d) :

N.S.Hr.Sec.School, Theni Page 8


Chapter -10 Python Classes and Objects

1.Which of the following are the key features of an Object Oriented Programming language?
(a) Constructor and Classes (b) Constructor and Object
(c) Classes and Objects (d) Constructor and Destructor

2.Functions defined inside a class:

(a) Functions (b) Module (c) Methods (d) section

3.Class members are accessed through which operator?


(a) & (b) . (c) # (d) %

4.Which of the following method is automatically executed when an object is created?


(a) __object__( ) (b) __del__( ) (c) __func__( ) (d) __init__( )

5.A private class variable is prefixed with


(a) __ (b) && (c) ## (d) **

6.Which of the following method is used as destructor?


(a) __init__( ) (b) __dest__( ) (c) __rem__( ) (d) __del__( )

7.Which of the following class declaration is correct?

(a) class class_name (b) class class_name<> (

c) class class_name: (d) class class_name[ ]

8.Which of the following is the output of the following program? class Student:
def __init__(self, name):
self.name=name
S=Student(“Tamil”)

(a) Error (b) Tamil (c) name (d) self

9.Which of the following is the private class variable?

(a) __num (b) ##num (c) $$num (d) &&num

10. The process of creating an object is called as:

(a) Constructor (b) Destructor (c) Initialize (d) Instantiation

Chapter 11- Database Concepts


1. What is the acronym of DBMS?
a) DataBase Management Symbol b) Database Managing System
c) DataBase Management System d) DataBasic Management System

2 A table is known as
a) tuple b) attribute c) relation d)entity
N.S.Hr.Sec.School, Theni Page 9
3 Which database model represents parent-child relationship?
a) Relational b) Network c) Hierarchical d) Object

4 Relational database model was first proposed by


a) E F Codd b) E E Codd c) E F Cadd d) E F Codder

5 What type of relationship does hierarchical model represents?


a) one-to-one b) one-to-many c) many-to-one d) many-to-many

6. Who is called Father of Relational Database from the following?


a) Chris Date b)Hugh Darween c) Edgar Frank Codd d) Edgar Frank Cadd

7. Which of the following is an RDBMS?


a) Dbase b) Foxpro c) Microsoft Access d) SQLite

8 What symbol is used for SELECT statement?


a) σ b) Π c) X d) Ω

9 A tuple is also known as


a) table b) row c) attribute d) field

10. Who developed ER model?


a) Chen b) EF Codd c) Chend d) Chand

Chapter 12 - Structured Query Language(SQL)

1.Which commands provide definitions for creating table structure, deleting relations, and modifying
relation schemas.
a. DDL b. DML c. DCL d. DQL

2.Which command lets to change the structure of the table?


a. SELECT b. ORDER BY c. MODIFY d. ALTER

3.The command to delete a table is


A) DROP B) DELETE C) DELETE ALL D) ALTER TABLE

4.Queries can be generated using


a. SELECT b. ORDER BY c. MODIFY d. ALTER

5.The clause used to sort data in a database

a. SORT BY b. ORDER BY c. GROUP BY d. SELECT

Chapter 13- Python and CSV Files

1.A CSV file is also known as a ….

(A) Flat File (B) 3D File (C) String File (D) Random File

N.S.Hr.Sec.School, Theni Page 10


2.The expansion of CRLF is

(A) Control Return and Line Feed (B) Carriage Return and Form Feed
(C) Control Router and Line Feed (D) Carriage Return and Line Feed

3.Which of the following module is provided by Python to do several operations on the CSV files?

(A) py (B) xls (C) csv (D) os

4.Which of the following mode is used when dealing with non-text files like image or exe files?
(A) Text mode (B) Binary mode (C) xls mode (D) csv mode

5.The command used to skip a row in a CSV file is


(A) next() (B) skip() (C) omit() (D) bounce()

6.Which of the following is a string used to terminate lines produced by writer()method of csv
module?
(A) Line Terminator (B) Enter key (C) Form feed (D) Data Terminator

7.What is the output of the following program? import csv


d=csv.reader(open('c:\PYPRG\ch13\city.csv'))
next(d)
for row in d: print(row)

if the file called “city.csv” contain the following details


chennai,mylapore
mumbai,andheri

A) chennai,mylapore (B) mumbai,andheri (C) chennai (D) chennai,mylapore

8.Which of the following creates an object which maps data to a dictionary?

(A) listreader() (B) reader() (C) tuplereader() (D) DicReader ()

9.Making some changes in the data of the existing file or adding more data is called

(A)Editing (B) Appending (C) Modification (D) Alteration

10.What will be written inside the file test.csv using the following program import csv

D = [['Exam'],['Quarterly'],['Halfyearly']]
csv.register_dialect('M',lineterminator = '\n')
with open('c:\pyprg\ch13\line2.csv', 'w') as f:
wr = csv.writer(f,dialect='M')
wr.writerows(D)
f.close() Prepared By
S.Ganesh Kumar, B.Sc., B.Ed., M.S.I.T.,

N.S.Hr.Sec.School, Theni Page 11


Exam,
Quarterly,
Halfyearly

Chapter 14 -Importing C++ Programs In Python

1. Which of the following is not a scripting language?

(A) JavaScript (B) PHP (C) Perl (D) HTML

2. Importing C++ program in a Python program is called

(A) wrapping (B) Downloading (C) Interconnecting (D) Parsing

3.The expansion of API is


(A) Application Programming Interpreter (B) Application Programming Interface
(C) Application Performing Interface (D) Application Programming Interlink

4.A framework for interfacing Python and C++ is

(A) Ctypes (B) SWIG (C) Cython (D) Boost

5.Which of the following is a software design technique to split your code into separate parts?
(A) Object oriented Programming (B) Modular programming
(C) Low Level Programming (D) Procedure oriented Programming

6.The module which allows you to interface with the Windows operating system is
(A) OS module (B) sys module (c) csv module (d) getopt module

7. getopt() will return an empty array if there is no error in splitting strings to

(A) argv variable (B) opt variable (c)args variable (d) ifile variable

8.Identify the function call statement in the following snippet.


if __name__ =='__main__':
main(sys.argv[1:])

(A) main(sys.argv[1:]) (B) __name__ (C) __main__ (D) argv


9.Which of the following can be used for processing text, numbers, images, and scientific data?
(A) HTML (B) C (C) C++ (D) PYTHON

10. What does __name__ contains ?


(A) c++ filename (B) main() name (C) python filename (D) os module name
N.S.Hr.Sec.School, Theni Page 12
Chapter 15- Data Manipulation Through SQL
1.Which of the following is an organized collection of data?

(A) Database (B) DBMS (C) Information (D) Records

2.SQLite falls under which database system?

(A) Flat file database system (B) Relational Database system

(C) Hierarchical database system (D) Object oriented Database system

3. Which of the following is a control structure used to traverse and fetch the records of the
database?

(A) Pointer (B) Key (C) Cursor (D) Insertion point

4. Any changes made in the values of the record should be saved by the command

(A) Save (B) Save As (C) Commit (D) Oblige

5.Which of the following executes the SQL command to perform some action?

(A) Execute() (B) Key() (C) Cursor() (D) run()

6. Which of the following function retrieves the average of a selected column of rows in a table?

(A) Add() (B) SUM() (C) AVG() (D) AVERAGE()

7.The function that returns the largest value of the selected column is

(A) MAX() (B) LARGE() (C) HIGH() (D) MAXIMUM()

8. Which of the following is called the master table?

(A) sqlite_master (B) sql_master (C) main_master (D) master_main

9. The most commonly used statement in SQL is

(A) cursor (B) select (C) execute (D) commit

10. Which of the following clause avoide the duplicate?

(A) Distinct (B) Remove (C) Where (D) GroupBy

Chapter 16 -Data Visualization Using Pyplot: Evaluation

1.Which is a python package used for 2D graphics?

a. matplotlib.pyplot b. matplotlib.pip c.matplotlib.numpy d. matplotlib.plt

2.Identify the package manager for Python packages, or modules.

a. Matplotlib b. PIP c. plt.show() d. python package

N.S.Hr.Sec.School, Theni Page 13


3.Read the following code: Identify the purpose of this code and choose the right option from the
following.

C:\Users\YourName\AppData\Local\Programs\Python\Python36-32\Scripts>pip – version

a. Check if PIP is Installed b. Install PIP c. Download a Package d. Check PIP version

4.Read the following code: Identify the purpose of this code and choose the right option from the
following.

C:\Users\Your Name\AppData\Local\Programs\Python\Python36-32\Scripts>pip list

a. List installed packages b. list command c. Install PIP d. packages installed

5.To install matplotlib, the following function will be typed in your command prompt. What does “-
U”represents?
Python –m pip install –U pip

a. downloading pip to the latest version b. upgrading pip to the latest version
c. removing pip d. upgrading matplotlib to the latest version
6. Observe the output figure. Identify the coding for obtaining this output.

a. import matplotlib.pyplot as plt b. import matplotlib.pyplot as plt


plt.plot([1,2,3],[4,5,1]) plt.plot([1,2],[4,5])
plt.show() plt.show()

7. Read the code:


a. import matplotlib.pyplot as plt
b. plt.plot(3,2)
c. plt.show()
Identify the output for the above coding.

Answer: (C)

8.Which key is used to run the module? a. F6 b. F4 c. F3 d. F5


N.S.Hr.Sec.School, Theni Page 14
9.Identify the right type of chart using the following hints.

Hint 1: This chart is often used to visualize a trend in data over intervals of time.
Hint 2: The line in this type of chart is often drawn chronologically.

a. Line chart b. Bar chart c. Pie chart d. Scatter plot

10. Read the statements given below. Identify the right option from the following for pie chart.
Statement A: To make a pie chart with Matplotlib, we can use the plt.pie() function.

Statement B: The autopct parameter allows us to display the percentage value using the Python string
formatting.

a. Statement A is correct b. Statement B is correct


c. Both the statements are correct d. Both the statements are wrong

Two mark questions:


1) Why strlen is called pure function? (L1)
strlen is a pure function because the function takes one variable as a parameter, and accesses
it to find its length. This function reads external memory but does not change it, and the value
returned derives from the external memory accessed.

ffect
ff
2) What is the side eff of impure function. Give example. (L1)
If a function modifies the variable outside the function is called as side effect and such
functions are called as impure functions. For example the mathematical function random() will give
different outputs for the same function call.
fferentiate pure and impure functions. (L1)
ff
3) Diff
Pure Function Impure Function
The return value of the pure functions solely The return value of the impure functions does
depends on its arguments passed. not solely depend on its arguments passed.
Hence, if you call the pure functions with the Hence, if you call the impure functions with the
same set of arguments, you will always get same set of arguments, you might get the different
the same return values. return values For example, random().
They do not modify the arguments which They may modify the arguments which are passed
are passed to them to them

4) What is abstract data type? (L2)


Abstract Data type (ADT) is a type (or class) for objects whose behavior is defend by a set of
value and a set of operations.

fferentiate
ff
5) Diff constructors and selectors. (L2)
Constructors are functions that build the abstract data type. Selectors are functions that
retrieve information from the data type.
6) What is a Pair? Give an example. (L2)
Any way of bundling two values together into one can be considered as a pair. Lists are a
common method to do so. Therefore List can be called as Pairs.
Ex: lst[(0, 10), (1, 20)]
N.S.Hr.Sec.School, Theni Page 15
7) What is a scope? (L3)
Scope refers to the visibility of variables, parameters and functions in one part of a program to
another part of the same program. In other words, which parts of your program can see or use it.

8) What is Mapping? (L3)


The process of binding a variable name with an object is called mapping. = (equal to sign) is used
in programming languages to map the variable and object.

9) How Python represents the private and protected Access specifies? (L3)
Python prescribes a convention of prefixing the name of the variable/method with single or
double underscore to emulate the behaviour of protected and private access specifies.

10) What is an Algorithm? (L4)


* An algorithm is a finite set of instructions to accomplish a particular task.
* It is a step-by-step procedure for solving a given problem.

11) Define Pseudo code. (L4)


Pseudo code is an informal way of programming description that does not require any strict
programming language syntax. It is used for creating an outline or a rough draft of a program.

12) What is Sorting? (L4)


Sorting is a process of ordering individual elements of a list, either in ascending or descending
order. Sorting arranges the data in a sequence which makes searching easier.
13) What is searching? Write its types. (L4)
Searching is the process of finding a given value position in a list of values. It decides whether a
search key is present in the data or not.
Types: 1) Linear Search 2) Binary Search 3) Jump Search

fferent
ff
14) What are the diff modes that can be used to test Python Program ? (L5)
In Python, programs can be written in two ways namely Interactive mode and Script mode.
The Interactive mode allows us to write codes in Python command prompt (>>>) whereas in script
mode programs can be written and stored as separate file with the
extension .py and executed.

15) Write short notes on Tokens. (L5)


Python breaks each logical line into a sequence of elementary lexical components known as
Tokens. The normal token types are
1) Identifiers, 2) Keywords, 3) Operators, 4) Delimiters and 5) Literals.

16) What is a literal? Explain the types of literals ? (L5)


Literal is a raw data given in a variable or constant. In Python, there are various types of
literals. 1) Numeric 2) String 3) Boolean

17) Write note on break statement. (L6)


The break statement terminates the loop containing it. When the break statement is executed, the
control flow of the program comes out of the loop and starts executing the segment of code after the
loop structure.

N.S.Hr.Sec.School, Theni Page 16


18) Define control structure. (L6)
A program statement that causes a jump of control from one part of the program to another is
called control structure or control statement.

19) Write a note on range( ) in loop. (L6)


The range() function returns a sequence of numbers, starting from 0 by default, and
increments by 1 (by default), and ends at a specified number.
range(start, stop, step)
Where, start – refers to the initial value
stop – refers to the final value
step – refers to increment value, this is optional part.

20) What are the main advantages of function? (L7)


• Reducing duplication of code
• Decomposing complex problems into simpler pieces
• Improving clarity of the code
• Reuse of code

21) What is meant by scope of variable? Mention its types. (L7)


Scope refers to the visibility of variables. In other words, which parts of your program can
see or use it. There are two types of scopes - local scope and global scope.

22) What is base condition in recursive function (L7)


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.

23) What is String? (L8)


String is a data type in python, which is used to handle array of characters. String is a
sequence of Unicode characters that may be a combination of letters, numbers, or special symbols
enclosed within single, double or even triple quotes.
Ex: “Welcome to Python”

24) How do you modify a string in Python? (L8)


As you already learnt, strings in python are immutable. That means, once you define a string
modifications or deletion is not allowed. If you want to modify the string, a new string value can be
assign to the existing string variable.

25) What is slicing? (L8)


Slice is a substring of a main string. A substring can be taken from the original string by
using [ ] operator and index or subscript values. Thus, [ ] is also known as slicing operator. Using
slice operator, we can slice one or more substrings from a main string.

N.S.Hr.Sec.School, Theni Page 17


Three mark questions:

1) Mention the characteristics of Interface. (L1)


• The class template specifies the interfaces to enable an object to be created and operated
properly.
• An object's attributes and behaviour is controlled by sending functions to the object.

2) Explain with example Pure and impure functions. (L1)


Pure functions are functions which will give exact result when the same arguments are passed.
For example the mathematical function sin (0) always results 0.
The variables used inside the function may cause side effects though the functions which are not
passed with any arguments. In such cases the function is called impure function. For example the
mathematical function random() will give different outputs for the same function call.

3) Explain with an example interface and implementation. (L1)


• Interface just defines what an object can do, but won’t actually do it.
• Implementation carries out the instructions defend in the interface.
• In object oriented programming classes are the interface and how the object is processed and
executed is the implementation.

fferentiate
ff
4) Diff Concrete data type and abstract datatype. (L2)
Concrete data type Abstract data type
A concrete data type is s data type whose An abstract data type is s data type whose
representation is known representation is unknown
Concrete data types or structures are direct Abstract data type offer a high level view
implementation of relatively simple concept. (use) of a concept independent of its
implementation.

fferent
ff
5) What are the diff ways to access the elements of a list. Give example. (L2)
The elements of a list can be accessed in two ways.
The first way is via our familiar method of multiple assignment. For example,
lst := [10, 20]
x, y := lst
In the above example x will become10 and y will become 20
A second method for accessing the elements in a list is by the element selection operator. For
example, lst[0] returns 10 and lst[1] returns 20

6) Define Global scope with an example. (L3)


A variable which is declared outside of all the functions in a program is known as global
variable. This means, global variable can be accessed inside or outside of all the functions in a
program. Consider the following example

N.S.Hr.Sec.School, Theni Page 18


7) Define Enclosed scope with an example. (L3)
A variable which is declared inside a function which contains another function definition
with in it, the inner function can also access the variable of the outer function. This scope is called
enclosed scope.

8) Why access control is required? (L3)


Access control is a security technique that regulates who or what can view or use resources in a
computing environment. It is a fundamental concept in security that minimizes risk to the object. In
other words access control is a selective restriction of access to data.

9) List the characteristics of an algorithm. (L4)


Input, Output, Finiteness, Definiteness, Effectiveness, Correctness, Simplicity, Portable,
Feasibility, Unambiguous, Independent.

10) Discuss about Algorithmic complexity and its types. (L4)


The complexity of an algorithm f (n) gives the running time and/or the storage space required by the
algorithm in terms of n as the size of input data.
Time Complexity
The Time complexity of an algorithm is given by the number of steps taken by the algorithm
to complete the process.
Space Complexity
Space complexity of an algorithm is the amount of memory required to run to its completion.

11) Write a note on Asymptotic notation. (L4)


Three asymptotic notations are mostly used to represent time complexity of algorithms:
(i) Big O : Big O is often used to describe the worst-case of an algorithm.
(ii) Big Ω : Big Omega is used to describe the lower bound (best-case) of an algorithm
(iii) Big Θ Big Theta -Θ notation is used to describe the average value or range within which the
actual time of execution of the algorithm will be.

12) What are the assignment operators that can be used in Python? (L5)
In Python, = is a simple assignment operator to assign values to variable. Let a = 5 and b = 10
assigns the value 5 to a and 10 to b these two assignment statement can also be given as a,b=5,10
that assigns the value 5 and 10 on the right to the variables a and b respectively. There are various
compound operators in Python like +=, -=, *=, /=, %=, **= and //= are also available.

13) Explain Ternary operator with example. (L5)


Ternary operator is also known as conditional operator that evaluate something based on a
condition being true or false. It simply allows testing a condition in a single line replacing the
multiline if-else making the code compact.
The Syntax is: Variable Name = [on_true] if [Test expression] else [on_false]
Example: min = a if a < b else b

N.S.Hr.Sec.School, Theni Page 19


14) What are string literals? Explain. (L5)
In Python a string literal is a sequence of characters surrounded by quotes. Python
supports single, double and triple quotes for a string. A character literal is a single character
surrounded by single or double quotes. Te value with triple-quote "' '" is used to give multiline string
literal.
Example: strings = "This is Python"
char = "C"
15) Write a note on if..else structure. (L6)
The if .. else statement provides control to check the true block as well as the false
block. Following is the syntax of ‘if..else’ statement.
if <condition>: if a%2==0:
statements-block 1 print (" an even number")
else: else:
statements-block 2 print (" an odd number")

16) Write the syntax of while loop. (L6)


while <condition>: With the while loop we can repeatedly execute a set of
statements block 1 statements as long as a condition is true.
[else: With the else statement we can run a block of code once when
statements block2] the condition is false.

fferences
ff
17) List the diff between break and continue statements. (L6)
Python break statement
The break statement terminates the loop containing it. Control of the program flows to the
statement immediately after the body of the loop.
Python continue statement
The continue statement is used to skip the rest of the code inside a loop for the current iteration
only. Loop does not terminate but continues on with the next iteration.
18) Write the rules of local variable. (L7)
1. A variable with local scope can be accessed only within the function/block that it is created in.
2. When a variable is created inside the function/block, the variable becomes local to it.
3. A local variable only exists while the function is executing.
4. The formate arguments are also local to function.

19) Differentiate ceil() and floor() function? (L7)


floor ( Returns the largest integer less than print (math.floor (x)) 26
) or equal to x print (math.floor (y)) -27
print (math.floor (z)) -24
ceil ( ) Returns the smallest integer greater print (math.ceil (x)) 27
than or equal to x print (math.ceil (y)) -26
print (math.ceil (z)) -23
20) What is composition in function? (L7)
The value returned by a function may be used as an argument for another function in a nested
manner. This is called composition. For example, if we wish to take a numeric value or an expression

N.S.Hr.Sec.School, Theni Page 20


as a input from the user, we take the input string from the user using the function input() and apply
eval() function to evaluate its value, for example: n1 = eval (input ("Enter a number: "))
21) How recursive function works? (L7)
1. Recursive function is called by some external code.
2. If the base condition is met then the program gives meaningful output and exits.
3. Otherwise, function does some required processing and then calls itself to continue
recursion.

22) Explain the following built-in functions. (a) id( ) (b) chr( ) (c) round( ) (d) type( ) (e) pow() (L7)
id (object) Returns the address of the object x=15 address of x is :
in memory print ('address of x :',id (x)) 1357486752
type (object) Returns the type of object for the x= 15.2 <class 'float'>
given single object. print (type (x))
round(number Returns the nearest integer to its x = round(5.76543, 2) 5.77
[,ndigits]) input. print(x)
pow (x,y) Returns the value of x to the power x = pow(4, 3) 64
of y (xy) print(x)
chr() Returns the Unicode character for x = chr(97) a
the given ASCII value. print(x)

23) Write a short about the followings with suitable example: (a) capitalize( ) (b) swapcase( ) (L8)

capitalize( ) Used to capitalize the first city="chennai" Chennai


character of the string print(city.capitalize())
swapcase() It will change case of every str1="tAMIL nADU" Tamil Nadu
character to its opposite case print(str1.swapcase())
vice-versa

24) What is the use of format( )? Give an example. (L8)


The format( ) function used with strings is very versatile and powerful function used for
formatting strings. Te curly braces { } are used as placeholders or replacement fields which get
replaced along with format( ) function. Example :
num1=int (input("Number 1: "))
num2=int (input("Number 2: "))
print ("Te sum of { } and { } is { }".format(num1, num2,(num1+num2)))

25) Write a note about count( ) function in python. (L8)


count(string,start,end) Returns the number of str1="Raja Raja Chozhan"
substrings occurs within the print(str1.count('Raja'))
given range.
2

Prepared By
S.Ganesh Kumar, B.Sc., B.Ed., M.S.I.T.,

N.S.Hr.Sec.School, Theni Page 21


Five mark questions:
1) What are called Parameters and write a note on
(i) Parameter without Type (ii) Parameter with Type (L1)

Parameters are the variables in a function definition and arguments are the values which are passed
to a function definition.

Parameter without Type


Let us see an example of a function definition:

(requires: b>=0 )
(returns: a to the power of b)
let rec pow a b:=
if b=0 then 1
else a * pow a (b-1)

In the above function definition variable ‘b’ is the parameter and the value which is passed to the
variable ‘b’ is the argument. Note we have not mentioned any types: (data types). Some language
compiler solves this type (data type) inference problem algorithmically, but some require the type to
be mentioned.

Parameter with Type


Now let us write the same function definition with types for some reason:

(requires: b> 0 )
(returns: a to the power of b )
let rec pow (a: int) (b: int) : int :=
if b=0 then 1
else a * pow b (a-1)

Te syntax to define functions is close to the mathematical usage: the definition is


introduced by the keyword let, followed by the name of the function and its arguments;
then the formula that computes the image of the argument is written after an = sign.

2) What is a List? Why List can be called as Pairs. Explain with suitable example (L2)

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 lst := [10, 20]

The elements of a list can be accessed in two ways. Te first way is via our familiar method of
multiple assignment.

N.S.Hr.Sec.School, Theni Page 22


lst := [10, 20]
x, y := lst

In the above example x will become10 and y will become 20

A second method for accessing the elements in a list is by the element selection operator, also
expressed using square brackets.

lst[0] returns 10 and lst[1] returns 20


In both the example mentioned above mathematically we can represent list similar to a set.
lst[(0, 10), (1, 20)] – where (0, 10) (1, 20)

Any way of bundling two values together into one can be considered as a pair. Lists are a common
method to do so. Therefore List can be called as Pairs.

3) How will you facilitate data abstraction. Explain it with suitable example (L2)

Data abstraction replicate how we think about the world. For example, when you want to drive a
car, you don’t need to know how the engine was built or what kind of material the tires are made of.
You just have to know how to turn the wheel and press the gas pedal. To facilitate data abstraction,
you will need to create two types of functions: constructors and selectors.

For example, say you have an abstract data type called city. This city object will hold the city’s
name, and its latitude and longitude. To create a city object, you’d use a function like
city = makecity (name, lat, lon)

The following pseudo code will compute the distance between two city objects:

As you already know that Constructors are functions that build the abstract data type. In the
above pseudo code the function which creates the object of the city is the constructor.
Here makecity (name, lat, lon) is the constructor which creates the object city.

Selectors are nothing but the functions that retrieve information from the data type. Therefore in the
above code

• getname(city)
• getlat(city)
• getlon(city)

are the selectors because these functions extract the information of the city object.
N.S.Hr.Sec.School, Theni Page 23
4) Explain the types of scopes for variable or LEGB rule with example. (L3)

Scope refers to the visibility of variables, parameters and functions in one part of a program to
another part of the same program. The LEGB rule is used to decide the order in which the scopes are
to be searched for scope resolution.

Local Scope

Local scope refers to variables defend in current function. Always, a function will first look
up for a variable name in its local scope. Only if it does not find it there, the outer scopes are
checked.

Enclosed Scope

A variable which is declared inside a function which contains another function definition with
in it, the inner function can also access the variable of the outer function. This scope is called
enclosed scope.
Global Scope
A variable which is declared outside of all the functions in a program is known as global
variable. This means, global variable can be accessed inside or outside of all the functions in a
program.
Built-in Scope
Any variable or module which is defend in the library functions of a programming language has
Built-in or module scope. They are loaded as soon as the library files are imported to the program.

5) Write any five benefits in using modular programming. (L3)


• Less code to be written.
• A single procedure can be developed for reuse, eliminating the need to retype the code many
times.
• Modular programming allows many programmers to collaborate on the same application.
• The code is stored across multiple files.
• Code is short, simple and easy to understand.
• Errors can easily be identified, as they are localized to a subroutine or function.

N.S.Hr.Sec.School, Theni Page 24


• The same code can be used in many applications.

6) Explain the characteristics of an algorithm. (L4)


• Input : Zero or more quantities to be supplied.
• Output : At least one quantity is produced.
• Finiteness : Algorithms must terminate after finite number of steps.
• Correctness : The algorithms should be error free.
• Simplicity : Easy to implement.
• Feasibility : Should be feasible with the available resources.
• Portable : An algorithm should be generic, independent of any programming language.

7) Discuss about Linear search algorithm. (L4)


Linear search also called sequential search is a sequential method for finding a particular value in
a list. This method checks the search element with each element in sequence until the desired
element is found or the list is exhausted. In this searching algorithm, list need not be ordered.
Pseudo code
1. Traverse the array using for loop
2. In every iteration, compare the target search key value with the current value of the list.
3. If the values match, display the current index and value of the array
4. If the values do not match, move on to the next array element.
5. If no match is found, display the search element not found.
To search the number 25 in the array given below, linear search will go step by step in a
sequential order starting from the first element in the given array if the search element is found that
index is returned otherwise the search is continued till the last index of the array. In this example
number 25 is found at index number 3.
Example:
Input: values[] = {10, 12, 20, 25, 30, 35}
target = 25
Output: 3

8) What is Binary search? Discuss with example. (L4)


Binary search also called half-interval search algorithm. It finds the position of a search element
within a sorted array. The binary search algorithm can be done as divide-and-conquer search
algorithm and executes in logarithmic time.
Pseudo code for Binary search
1. Start with the middle element:

o If the target value is equal to the middle element of the array, then return the index of
the middle element.
o If not, then compare the middle element with the target value,

N.S.Hr.Sec.School, Theni Page 25


If the target value is greater than the number in the middle index, then pick the
elements to the right of the middle index, and start with Step 1.
If the target value is less than the number in the middle index, then pick the
elements to the left of the middle index, and start with Step 1.
2. When a match is found, return the index of the element matched.
3. If no match is found, then return -1

For a binary search to work, it is mandatory for the target array to be sorted. The following is our
sorted array and let us assume that we need to search the location of value 31 using binary
search.

First, we shall determine half of the array by using this formula −


mid = low + (high - low) / 2
Here it is, 0 + (9 - 0 ) / 2 = 4 (integer value of 4.5). So, 4 is the mid of the array.

Now we compare the value stored at location 4. We find that the value at location 4 is 27, which
is not a match. As the value is greater than 27, we know that the target value must be in the
upper portion of the array.

We change our low to mid + 1 and find the new mid value again.
low = mid + 1
mid = low + (high - low) / 2
Our new mid is 7 now. We compare the value stored at location 7 with our target value 31.

The value stored at location 7 is not a match, rather it is more than what we are looking for. So,
the value must be in the lower part from this location.

Hence, we calculate the mid again. This time it is 5.

N.S.Hr.Sec.School, Theni Page 26


We compare the value stored at location 5 with our target value. We find that it is a match.

We conclude that the target value 31 is stored at location 5.

9) Explain the Bubble sort algorithm with example. (L4)


Bubble Sort

Bubble sort is based on the idea of repeatedly comparing pairs of adjacent elements and then
swapping their positions if they exist in the wrong order.

Implementing Bubble Sort Algorithm

Following are the steps involved in bubble sort(for sorting a given array in ascending order):

1) Starting with the first element(index = 0), compare the current element with the next element of
the array.

2) If the current element is greater than the next element of the array, swap them.

3) If the current element is less than the next element, move to the next element. Repeat Step 1.

Lets try to understand the pseudo code with an example: A [ ] = { 7, 4, 5, 2}

The sorted array is A[]={2,4,5,7}.

10) Explain the concept of Dynamic programming with suitable example. (L4)
Dynamic programming is an algorithmic design method that can be used when the solution to a
problem can be viewed as the result of a sequence of decisions. Dynamic programming approach is
N.S.Hr.Sec.School, Theni Page 27
similar to divide and conquer. The given problem is divided into smaller and yet smaller possible
sub-problem.
Steps to do Dynamic programming
• The given problem will be divided into smaller overlapping sub-problems.
• An optimum solution for the given problem can be achieved by using result of smaller sub-
problem.
Dynamic programming approach : Fibonacci Series
The following example shows a simple Dynamic programming approach for the generation of
Fibonacci series.
Initialize f0=0, f1 =1
step-1: Print the initial values of Fibonacci f0 and f1
step-2: Calculate fbanocci fb ← f0 + f1
step-3: Assign f0← f1, f1← fb
step-4: Print the next consecutive value of fbanocci fb
step-5: Goto step-2 and repeat until the specified number of terms generated.
For example if we generate fibobnacci series upto 10 digits, the algorithm will generate
the series as shown below: 0 1 1 2 3 5 8 13 21 34 55

11) Discuss in detail about Tokens in Python (L5)


Python breaks each logical line into a sequence of elementary lexical components known as
Tokens. The normal token types are 1) Identifiers, 2) Keywords, 3) Operators,
4) Delimiters and 5) Literals.
Identifiers
An Identifier is a name used to identify a variable, function, class, module or object.
Example of valid identifiers Sum, total_marks, regno, num1
Keywords
Keywords are special words used by Python interpreter to recognize the structure of
program. As these words have specific meaning for interpreter, they cannot be used for any
other purpose.
Example : if, for, switch, break, continue, return, pass
Operators
In computer programming languages operators are special symbols which represent
computations, conditional matching etc. The value of an operator used is called operands.
Operators are categorized as Arithmetic, Relational, Logical, Assignment etc. Value and
variables when used with operator are known as operands.
Delimiters
Python uses the symbols and symbol combinations as delimiters in expressions, lists,
dictionaries and strings. Following are the delimiters.
Ex: ( , ) , [ , ] , { , }
Literals

N.S.Hr.Sec.School, Theni Page 28


Literal is a raw data given in a variable or constant. In Python, there are various types
of literals. 1) Numeric 2) String 3) Boolean

12) Write a detailed note on if..else..elif statement with suitable example. (L6)
When we need to construct a chain of if statement(s) then ‘elif ’ clause can be used
instead of ‘else’.
if <condition-1>:
statements-block 1
elif <condition-2>:
statements-block 2
else:
statements-block n
In the syntax of if..elif..else mentioned above, condition-1 is tested if it is true then
statements-block1 is executed, otherwise the control checks condition-2, if it is true statements
block2 is executed and even if it fails statements-block n mentioned in else part is executed.
Example:
num=int(input(“Enter a number “))
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")

13) Explain the different types of function with an example. (L7)


Functions are named blocks of code that are designed to do specific job.
Types:
1)Built-in Functions 2)User-defined Functions
3) Lambda Functions 4) Recursion Functions
Built-in Functions:
The Python interpreter has a number of functions that are always available for use.
These functions are called built-in functions. For example, print() function prints the given object
to the standard output device (screen) or to the text stream file.
User-defined Functions:
Functions that we define ourselves to do certain specific task are referred as user-defined functions.
User-defined functions help to decompose a large program into small segments.
Syntax for user defined function:
def <function_name ([parameter1, parameter2…] )> :
<Block of Statements>
return <expression / None>

N.S.Hr.Sec.School, Theni Page 29


Lambda or Anonymous function:
In Python, anonymous function is a function that is defend without a name. While
normal functions are defend using the def keyword, in Python anonymous functions are
defined using the lambda keyword. Hence, anonymous functions are also called as lambda
functions.
Syntax is: lambda [argument(s)] :expression
Ex: double = lambda x: x * 2
Recursive functions :
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. 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.

14) Explain the scope of variables with an example. (L7)


Scope of variable refers to the part of the program, where it is accessible, i.e., area where
you can refer (use) it. We can say that scope holds the current set of variables and their values. Two
types of scopes are - local scope and global scope.
Local Scope
A variable declared inside the function's body or in the local scope is known as local
variable. A local variable only exists while the function is executing.
Example:
def loc():
y=0 # local scope
print(y)
loc()
Output: 0
Global Scope
A variable, with global scope can be used anywhere in the program. It can be created by
defining a variable outside the scope of any function/block. When we define a variable outside a
function, it’s global by default. You don’t have to use global keyword. We use global keyword to
read and write a global variable inside a function.
Example:
c=1 # global variable
def add():
print(c)
add() Output: 1

15) Explain about string operators in python with suitable example. (L8)
Python provides the following operators for string operations. These operators are useful to
manipulate string.

N.S.Hr.Sec.School, Theni Page 30


(i) Concatenation (+)
Joining of two or more strings is called as Concatenation. The plus (+) operator is used to
concatenate strings in python.
Example
>>> "welcome" + "Python"
'welcomePython'
(ii) Append (+ =)
Adding more strings at the end of an existing string is known as append. The operator
+= is used to append a new string with an existing string.
Example
>>> str1="Welcome to "
>>> str1+="Learn Python"
>>> print (str1)
Welcome to Learn Python
(iii) Repeating (*)
The multiplication operator (*) is used to display a string in multiple number of times.
Example
>>> str1="Welcome "
>>> print (str1*4)
Welcome Welcome Welcome Welcome
(iv) String slicing
Slice is a substring of a main string. A substring can be taken from the original string
by using [ ] operator and index or subscript value. The syntax is,
str[start:end]
>>> str1="THIRUKKURAL"
>>> print (str1[0])
T

16) Briefly explain about while loop with example. (L6)


A loop statement allows to execute a statement or group of statements multiple times.
The syntax of while loop in Python has the following syntax:
while <condition>:
statements block 1
[else:
statements block2]

N.S.Hr.Sec.School, Theni Page 31


In the while loop, the condition is any valid Boolean expression returning True or
False. The else part of while is optional part of while. The statements block1 is kept executed
till the condition is True. If the else part is written, it is executed when the condition is tested
False. Recall while loop belongs to entry check loop type, that is it is not executed even once if
the condition is tested False in the beginning.
Example:
i=10
while (i<=15):
print (i,end='\t')
i=i+1
Output: 10 11 12 13 14 15
17) Briefly explain about for loop with example. (L6)
A loop statement allows to execute a statement or group of statements multiple times. for
loop is the most comfortable loop. It is also an entry check loop. The condition is checked in the
beginning and the body of the loop(statements-block 1) is executed if it is only
True otherwise the loop is not executed.
for counter_variable in sequence:
statements-block 1
[else: # optional block
statements-block 2]
Usually in Python, for loop uses the range() function in the sequence to specify the initial,
final and increment values.

Example:
for i in range (2,10,2):
print (i, end=' ')

Output: 2 4 6 8

----- & -----


• WAMP stands for “Windows, Apache, MySQL and PHP”
• DML - Data Manipulation Language
• DDL - Data Defnition Language
• DCL - Data Control Language
• TCL - Transaction Control Language

N.S.Hr.Sec.School, Theni Page 32


• DQL - Data Query Language
• SQL – Structured Query Language
• DBMS: DataBase Management System
• RDBMS: Relational DataBase Management System
• GIS: Geographic Information System
• DBA: DataBase Administrator
• ADT - Abstract Data type
• CDT - Concrete data types
• LEGB rule - Local Enclosed Global Built-in
• Graphical User Interface (GUI)
• Integrated Development Environment (IDE)
• IDLE (Integrated Development Learning Environment)
• Python is an Object Oriented Programming language.
• In Python, there is a special function called “init” is used as Constructor.
• In Python, __del__( ) method is used as destructor.
• A variable prefixed with double underscore is becomes private in nature.
• Database Normalization was proposed by Dr.Edgar F Codd
• Normalization reduces data redundancy and improves data integrity
• SQL is a language that helps to create and operate relational databases.
• MySQL is a database management system
• The DDL provides statements for creation and deletion of tables.
• The DML provides statements to insert, update and delete data of a table.
• The DCL provides authorization commands to access data.
• The TCL commands are used to manage transactions in a database.
• The DQL commands help to generate queries in a database.
• The CREATE TABLE command creates a new table.
• CSV - Comma-Separated Values
• Excel is a binary flee whereas CSV format is a plain text format
• The two ways to read a CSV flee are using csv.reader() function and using DictReader
class.
• csv.reader and csv.writer work with list/tuple, while csv.DictReader and csv.DictWriter work
with dictionary . Prepared By
• API – Application Programming Interface S.Ganesh Kumar, B.Sc., B.Ed., M.S.I.T.,

N.S.Hr.Sec.School, Theni Page 33

You might also like