Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

+2 CS MLM 1-36

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

HIGHER SECONDARY SECOND YEAR

COMPUTER SCIENCE
CHAPTER – 1 (FUNCTION)
ONE MARK :-
1. ___ is the small sections of code that are used to perform a particular task
repeatedly.(Subroutines)
2. ___ is the basic building blocks of computer programs (Subroutines)
3. ___ is a unit of code that is often defined within a greater code structure. (Function)
4. The variables used in a function definition are called as ___ (Parameters)
5. The values passed to a function definition are called ___ (Arguments)
6. Which is mandatory to write the type annotations in the function definition? ( )
7. ___ is a distinct syntactic block. (Definition)
8. ___ is the keyword used to define function. (let)
9. A function definition which call itself is called ___. (Recursive function)
10. ___ keyword is used to define a recursive function. (let rec)
11. All functions are ___ definitions. (static)
TWO MARKS :-
12. What is a Subroutine?
Subroutines are small sections of code that are used to perform a particular task that
can be used repeatedly.
13. Define Function with respect to Programming language.
A function is a unit of code that works on many kinds of inputs and produces a
concrete output.
14. Write the syntax for Recursive function.
let rec fn a1 a2 a3…an := k
FIVE MARKS :-
15. What are called Parameters and write a note on
a) Parameter without type b) Parameter with type
❖ Parameters are the variables in a function definition.
❖ Parameter without type :-
✓ If we have not mentioned any type, then
some language compiler solves this type
inference problem algorithmically. Let us see
an example
✓ In the above function definition variable ‘b’ is
the parameter.
✓ if expression can return 1 in the then branch, the entire if expression has type int.
✓ ‘b’ is compared to 0 with the equality operator. So ‘b’ is also type of int.
✓ Since ‘a’ is multiplied with another expression using the * operator ‘a’ must be an int.

1
❖ Parameter with type :-
✓ There are times we may want to explicitly write down
types.This is useful on times when you get a type error
from the compiler. Let us see an example
✓ In the above function definition, the type annotations for
‘a’ and ‘b’ are given.
✓ Return type is also specified here.
✓ To write the type annotations parenthesis( ) is mandatory.
✓ Explicitly annotating the types can help with debugging.

CHAPTER – 2 (DATA ABSTRACTION)


ONE MARK :-
1. The process of providing only the essentials and hiding the details is known as ___.
(Abstraction)
2. ___ provides modularity to a program. (Abstraction)
3. ___ are the representation for Abstract Data Types. (Classes)
4. ___ are the functions that build the Abstract Data Types. (Constructors)
5. ___ are the functions that retrieve information from the data type. (Selectors)
6. In function definition, comments are identified using ___ ( - - )
7. The data type whose representation is known are called ___. (Concrete datatype)
8. The data type whose representation is unknown are called ___. (Abstract datatype)
TWO MARKS :-
9. Define Abstraction.
The process of providing only the essentials and hiding the details is known as
Abstraction.
10. What is Abstract data type(ADT)?
Abstract data type is a type for objects whose behavior is defined by a set of value and
a set of operations.
11. Differentiate Constructors and Selectors.
❖ Constructors are functions that build the abstract data type.
❖ Selectors are functions that retrieve information from the data type.
THREE MARKS :-
12. Identify Which of the following are constructors ad selectors?
❖ N1=number() ------- Constructor
❖ acceptnum(n1) ------- Selector
❖ displaynum(n1) ------- Selector
❖ eval(a/b) ------- Selector
❖ x,y=makeslope(m),makeslope(n) ------- Constructor
❖ display() ------- Selector
FIVE MARKS :-
13. How will you facilitate data abstraction? Explain it with suitable example.
2
❖ To facilitate data abstraction, you need to create two types of functions: Constructors
and Selectors
❖ Constructors are functions that build the abstract data type.
❖ Selectors are functions that retrieve information from the data type.
➢ For example, To create a city object, you’d use a function
➢ city=makecity(name,lat,lon)
➢ To extract the information of a city object, you’d use functions
➢ getname(city)
➢ getlat(city)
➢ getlon(city)
➢ In the above example, makecity() is the constructor which creates the object city
➢ getname(city),getlat(city),getlon(city) are the selectors because these functions
extract the information of the city object.

CHAPTER – 3 (SCOPING)
ONE MARK :-
1. Which refers to the visibility of variables in one part of a program to another part of the same
program?(Scope) .
2. The process of binding a variable name with an object is called ___. (Mapping)
3. Which is used in programming languages to map the variable and object? (=)
4. Containers for mapping names of variables to objects is called ___. (Namespaces)
5. Which rule is used to decide the order in which the scopes are to be searched? (LEGB)
6. ___ refers to variables defined in current function. (Local scope)
7. A variable which is declared outside of all the functions in a program is called ___. (Global
variable)
8. In which scope, a variable declared in outer function can also accessed by the inner function?
(Enclosed scope)
9. A variable or module which is defined in the library functions of a programming language has
___ scope. (Built-in)
TWO MARKS :-
10. What is a scope?
Scope refers to the visibility of variables, parameters and functions in one part of a
program to another part of the same program.
11. What is Mapping?
❖ 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.
12. What do you mean by Namespaces?
Namespaces are containers for mapping names of variables to objects.
FIVE MARKS :-
13. Explain the types of scopes for variables:
Local Scope :-
❖ Local scope refers to variables defined in current function.
3
❖ A function will first look up for a variable name in its local scope.
❖ If it does not find it there, the outer scopes are checked. For example

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 functions in a program. For
example

Enclosed Scope :-
❖ A function within another function is called Nested function.
❖ A variable declared in an Outer function,which contains another inner function can
also access the variable of this outer function.For example

Built-in Scope :-
❖ The built-in scope has all the names that are pre-loaded into the program scope when
we start the compiler or interpreter.
❖ Any variable which is defined in the library functions of a programming language has
Built-in scope.
❖ This is the widest scope. For example

4
14. Explain LEGB rule with an example.
❖ LEGB rule is used to decide the order in which the scopes are to be searched for scope
resolution.
❖ It defines the order in which variables have to be mapped to the object.
For example

❖ In the above example, the variable name x resides in different scopes.


❖ There is a rule followed here, in order to decide from which scope a variable has to be
picked.
❖ The scopes are listed below in terms of hierarchy (highest to lowest)

CHAPTER – 4 (ALGORITHMIC STRATEGIES)


ONE MARK :-
1. The way of defining an algorithm is called ___ .(Algorithmic Strategy)

5
2. The word comes from the name of a Persian mathematician Abu Jafar Mohammed ibn-I Musa
al Khowarizmi is called as ___ (Algorithm)
3. An algorithm that yields expected output for a valid input is called ___ (Algorithmic solution)
4. Which sorting algorithm requires minimum number of swaps? (Selection sort)
5. The complexity of linear search algorithm is ___.O(n)
6. Which sorting algorithm has the lowest worst case complexity?(Merge sort)
7. Which is not a stable sorting algorithm?(Selection sort)
8. Time complexity of bubble sort in best case is ___.O(n)
9. Linear search algorithm is also called as ___.(Sequential search)
10. Binary search algorithm is also called as ___.(Half-interval search)
TWO MARKS :-
11. What is an Algorithm?
❖ An algorithm is a finite set of instructions to accomplish a particular task.
❖ It is a step-by-step procedure for solving a problem.
12. Define Pseudo code.
❖ Pseudo code is an informal way of program description to solve the problem.
❖ It does not require any strict programming syntax.
13. Who is an Algorist?
❖ An Algorist is the person skilled in writing Algorithms.
14. What is Sorting?
❖ Sorting is the process of arranging information or data in an ordered sequence either
in ascending or descending order.
15. What is Searching? Write its types.
❖ Searching is the process of finding a particular data in a data structure.
❖ Types of searching
1. Linear search 2. Binary search
THREE MARKS :-
16. What are the different phases of analysis and performance evaluation of algorithm?
❖ A priori estimate : This is a theoretical performance analysis. In this analysis, efficiency
is measured by assuming the external factors.
❖ A posteriori testing : This is called performance measurement. In this analysis, actual
running time required for the algorithm execution are collected.
FIVE MARKS :-
17. Explain the characteristics of an algorithm.
❖ Input – Zero or more quantities to be supplied.
❖ Output –At least one quantity is produced.
❖ Finiteness –Algorithms must terminate after finite number of steps.
❖ Definiteness –All operations should be well defined.
❖ Effectiveness –Every instruction must be carried out effectively.
❖ Correctness – The algorithms should be error free.
❖ Simplicity –Easy to implement.
6
❖ Unambiguous –Algorithm should be clear and unambiguous.
❖ Feasibility –Should be feasible with the available resources.
❖ Portable –Should be independent of any programming language or operating system
and able to handle all range of inputs.
❖ Independent -Algorithm should have step-by-step directions, which should be
independent of any programming code.
18. Discuss about Linear search algorithm.
❖ Linear search is a sequential method for finding a particular value in a list.
❖ In this searching algorithm, list need not be ordered.
❖ Linear search is also called as Sequential search.
Pseudo code :-
❖ Traverse the array using for loop
❖ In every iteration, compare the target search key value with the current value of the
list.
➢ If the values match, display the current index and value of the array.
➢ If the values do not match, move on to the next array element.
❖ If no match is found, display the search element not found.

❖ In the above example, number 25 is found at index number 3


19. What is Binary search? Discuss with example.
❖ Binary search algorithm finds the position of a search element within a sorted array. It
is also called as half-interval search algorithm.
❖ It can be done as divide-and-conquer search algorithm.
Example:- Let us assume that the search element is 60 and we need to search the
index of search element.

❖ We find index of middle element of the array by using this formula.


➢ mid = low+(high-low)/2
➢ low=0 high=9
➢ mid=0+(9-0)/2 = 4


➢ low=mid+1=5 high=9
➢ mid=5+(9-5)/2=7

➢ low=5 high=mid-1=6
➢ mid=5+(6-5)/2

7
❖ The search element 60 is found at index 5.
❖ If the search element is not found, then display unsuccessful message.
20. Explain the Bubble sort algorithm with example.
❖ Bubble sort is a simple sorting algorithm.
❖ The algorithm starts at the beginning of the list of values stored in an array.
❖ It compares each pair of adjacent elements and swaps them if they are in the unsorted
order.
❖ This comparison and passed to be continued until no swaps are needed.
Pseudo code :-
❖ Start with the first element.
❖ If the current element is greater than the next element of the array, swap them.
❖ If the current element is less than the next, move to the next element.
❖ Go to step1 and repeat until end of the index is reached.
❖ Example :- Let us consider an array with values {15,11,16,12,14,13}

❖ The above pictorial example is for iteration-1


❖ At the end of all the iterations we will get the sorted values in an array as below.

CHAPTER-5 (PYTHON-VARIABLES AND OPERATORS)
ONE MARK :-
1. Who developed Python?(Guido Van Rossum)
2. ___Character is used to give comments in Python Program. (#)
3. ___symbol is used to print more than one item on a single line. Comma(,)
4. Comparative operator is also called as___operator. (Relational)
5. Conditional operator is also called as ___ operator.(Ternary)
6. Python breaks each logical line into a sequence of elementary lexical components known
as___. (Tokens)
8
7. Python shell can be used ___ ways.(Two)
8. IDLE expanded as _________________. (Integrated Development Learning Environment)
9. ___ is a text file containing python statements. (Script)
10. Which shortcut is used to create new python program ? (Ct+N)
TWO MARKS :-
11. What are the different modes that can be used to test Python Program?
Python shell can be used in two ways.(i) Interactive mode (ii) Script mode.
12. Write short note on Tokens.
Python breaks each logical line into a sequence of elementary lexical components
known as Tokens.
THREE MARKS :-
13. What is Literal?. What are the types of literals.
Literal is a raw data given in a variable or constant. In Python, There are various types
of Literal. (i)Numeric (ii) String (iii) Boolean
14. What is Escape Sequences?
In Python Strings, the backslash “\” is a special character, also called the “escape”
character. It is used in representing certain whitespace characters: “\t” is a tab, “\n” is a
newline, and “\r” is a carriage return.
Ex: >>> print (“It\’s raining)
O/P: It’s raining
15. Write short note on Conditional operator.
Ternary operator is also known as conditional operator that evaluate something based
on a condition being true or false.
Ex: min 50 if 49<50 else 70 # min=50
min 50 if 49>50 else 70 # min=70
16. Write a short note on input() function in python.
input( ) function :-
❖ The input( ) function is used to accept data as input at run time.
Syntax :
Variable=input(“Prompt string”)
❖ Prompt string in the syntax is a statement or message to the user.
❖ If prompt string is not given no message is displayed on the screen.
❖ The input( ) function takes the entered data and stored in the given variable.
❖ The input( ) function accepts all the data as string but not as numbers.
❖ If numeric value is required, the int( ) function is used to convert string data as
integer data explicitly.

9
FIVE MARKS :-
17. Explain Operators?
The value of an operator used is called operands, Operators are categorized as
Arithmetic, Relational, Logical, Assignment and Conditional.
(1) Arithmetic operators:+,-,*,/,%,**
(2) Relational or Comparative operators: ==,>,<,>=,<=,!=
(3) Logical operators: or,and,not
(4) Assignment operators: =,+=,-=
(5) Conditional operators: Ternary operator is also known as conditional operator that
evaluate something based on a condition being true or false
18. Discuss in detail about Tokens in Python?
Python breaks each logical line into a sequence of elementary lexical components
known as Tokens. Identifiers, Keywords, Operators, Delimiters, Literals.
Identifiers:-
An Identifier is a name used to identify a variable, function, class, module or object.
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. Eg: false, none, class etc…
Operators:-
The value of an operator used is called operands, Operators are categorized as
Arithmetic, Relational, Logical, Assignment and Conditional.
Delimiters:-
Python uses the symbols and symbol combinations as delimiters in expressions, lists,
dictionaries and strings. Eg: [ ,], {,},=etc…
Literals:-
Literal is a raw data given in a variable or constant. There are various types of literals:
Numeric, String and Boolean.

CHAPTER-6 (CONTROL STRUCTURES)


ONE MARK :-
1. How many important control structures are there in Python? (3)
2. What plays a vital role in Python programming? (Indentation)
3. Which statement is generally used as a placeholder? (pass)
4. Which is the most comfortable loop? (for)
5. elif can be considered to be abbreviation of else if
6. range(30,3,-3) will start the range values from 30 and end at 6
7. ___ statement allows to execute a statement or group of statements multiple times. (Loop)
8. ___ statement is used to unconditionally transfer the control from one part of the program to
another. (Jump)
10
9. Which statement is used to skip the remaining part of the loop and start with next iteration?
(Continue)
10. ___ is the optional part of while loop. (else)
TWO MARKS :-
11. List the control structure in Python.
There are three important control structures (1) Sequential (2) Alternative or
Branching (3) Iterative or Looping
12. Define control structure.
A program statement that causes a jump of control from one part of the program to
another is called control structure of control statement.
13. List the differences between break and continue statements.
The break statement terminates the loop containing it. Control of the program flows
to the statement immediately after the body of the loop.
Continue statement unlike the break statement is used to skip the remaining part of a
loop and start with next iteration.
THREE MARKS :-
14. Write note on if..elif…else structure.
When we need to construct a chain of if statements then ‘elif’ clause can be used
instead of ‘else’.
Syntax:
if<condition-1>:
statement block 1
elif<condition-1>:
statement block 2
else:
statement block n
15. Define pass.
Pass statement in Python programming is a null statement. Pass statement when
executed by the interpreter it is completely ignored.
16. Write a note on range( ) in loop.
❖ The range() function is used to generate a series of values.
❖ range() function has three arguments.
Syntax :
range(start,stop,step)

Start (optional) – Beginning value of series. Zero is the default beginning value.
Stop (required) – Upper limit of series. An integer number specifies at which position
to Stop. The stop value is not included in the series.
Step (optional) – It is an integer that specifies the increment of a number. The default
value is 1.
Example OUTPUT:
11 2468
FIVE MARKS :-
17. Write a detail note on if..else..elif statement with suitable example.
When we need to construct a chain of if statements then ‘elif’ clause can be used
instead of ‘else’.
Syntax:
if<condition-1>:
statement block 1
elif<condition-1>::
statement block 2
else:
statement block n
Example:
# To find the biggest of three numbers
a=int(input(“Enter the First Number:”))
b=int(input(“Enter the Second Number:”))
c=int(input(“Enter the Third Number:”))
Output :- Enter the First Number: 75
if a>b and a>c:
Enter the Second Number: 82
big=a
Enter the Third Number: 10
elif b>c :
big =b The biggest of three numbers is: 82
else:
big=c
print(“The biggest of three numbers is:”,big)
18. Write a detail note on looping constructs.
Python provides two types of looping constructs:
• while loop
• for loop
while loop:-
while loop is a entry check loop. while loop belongs to entry check loop type, that is it
is not executed even once if the condition is tested False in the begging.
Syntax:
while<condition>:

statement block 1

[else: statement block 2]

12
for loop:-

for loop is also entry check loop. The condition is checked in the beginning and the
body of the loop is executed if it is only True otherwise the loop is not executed.
Syntax:

for counter-variable in sequence:

statement block 1

[else:

statement block 2]

for loop uses the range() function in the sequence to specify the initial, final and
increment values. range () generates a list of values starting from start till stop-1.

CHAPTER-7 (PYTHON FUNCTIONS)


ONE MARK :-
1. ___keyword is used to begin the function block.(def )
2. ___ keyword is used to exit the function block. (return)
3. While defining a function ___symbol is used. (: colon)
4. A block within a block is called ___. (nested block)
5. ___function is called anonymous un-named function. (Lambda)
6. Which function can access only global variables ? (Lambda)
7. Which keyword is used to read and write a global variable inside a function ? (global)
TWO MARKS :-
8. What is function?
Functions are named blocks of code that are designed to do one specific job.
9. What are the main advantages of function?
• It avoids repetition and makes high degree of code reusing.
• It provides better modularity for your application.
10. Define “return” statement.
The return statement causes function to exit and returns a value to its caller. .
THREE MARKS :-
11. Write the different types of function.
We can divide functions into the following types:
(1) User-defined functions – Functions defined by the users themselves.
(2) Built-in functions – Functions that are inbuilt within python.
(3) Lambda functions – Functions that are anonymous un-named function.
(4) Recursion functions – Functions that calls itself is known as recursive.

13
12. Write the basic rules for global keyword in python.
Rules for using global keyword
• When we define a variable outside a function, it’s global by default. You don’t have
to use global keyword.
• We use global keyboard to read and write global variable inside a function.
• Use of global keyword outside a function has no effect.
13. What are the points to be noted while defining a function ?
• Function blocks begin with the keyword “def” followed by function name and
parenthesis().
• Input parameters should be placed within these parentheses when you define a
function.
• The code block always comes after colon(:) and is indented.
• The statement “return” exits a function, optionally passing back an expression to the
caller. A “return” with no arguments is the same as return None.
14. What is Anonymous(Lambda) function ? Write the syntax and explain lambda.
Anonymous function is a function that is defined without a name. In python,
anonymous functions are defined using lambda keyword.
Syntax :
lambda [argument(s)]:expression
Example :
sum=lambda arg1,arg2:arg1+arg2
FIVE MARKS :-
15. Explain the scope of variables in python with an example.
Scope of variable refers to the part of the program, where it is accessible, i.e area where
you can refer it. There are two types of scopes.
• Local scope
• Global scope
Local scope :-
A variable declared inside the function’s body or in the local scope is known as local
variable.
Rules of local variable:-
• A variable with local scope can be accessed only within the function that it is
created in.
• When a variable is created inside the function, the variable becomes local to it.
• A local variable only exits while the function is executing.
• The formal arguments are also local to function.

14
Example :
def loc( ):
y=0
print(y)
loc( )
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 function.
Rules for using global keyword :-
• When we define a variable outside a function, it’s global by default. You don’t have
to use global keyword.
• We use global keyboard to read and write global variable inside a function.
• Use of global keyword outside a function has no effect.
Example
c=1
def add( ):
print(c)
add( )

CHAPTER-8 (STRING AND STRING MANIPULATIONS)


ONE MARK :-
1. ___operator is used for concatenation.(+)
2. Strings in python are ___(Immutable)
3. ___is the slicing operator. [ ]
4. Defining strings within triple quotes allows creating: (Multiline Strings)
5. ___operator is used to display a string in multiple number of times. (*)
6. Which are used to access and manipulate the strings ? (Subscript)
7. ___ is a third argument in slicing operation. (Stride)
8. Which function is used to change all occurrences of a particular character in a string ?
(replace())
TWO MARKS :-
9. What is String ?
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.

15
10. How will you delete a string in python?
Python will not allow deleting a particular character in a string. Whereas you can
remove entire string variable using del command.
11. What will be the output for the following python code ?
>>>str = “Computer” OUTPUT :
>>>print(str*5)
Computer Computer Computer Computer Computer
THREE MARKS :-
12. What is Slicing? Give an example.
A substring can be taken from the original string by using Slice [ ] operator. Splitting
Substring is known as Slicing.
General Format :
Str[start:end]
Example :
OUTPUT :
>>>str = “THIRUKKURAL”
THIRU
>>>print(str[0:5]
13. What will be the output of the following python code ?
>>>str=”Tamilnadu” OUTPUT :
>>>print(str[:5]) TAMIL
>>>print(str[5:] NADU
>>>print(str[::-3]) UNM
FIVE MARKS :-
14. Explain about string operators in python with suitable example.
String Operators
U
1) Concatenation(+) :-
Joining of two or more strings is called as Concatenation. The plus(+)operator is used to
concatenate strings
Example : OUTPUT :

>>>”Welcome to “ + ”Python” Welcome to Python

(2) 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 : OUTPUT :
>>>s=”Computer “
>>>print(s+=”Science”) Computer Science

16
(3) Repeating(*) :-
The multiplication operator(*) is used to display a string in multiple number of times.
Example: OUTPUT :
>>>print(“Python”*3) Python Python Python

CHAPTER-9 (LISTS,TUPLES,SETS AND DICTIONARY)


ONE MARK :-
1. Which function is used to count the number of elements in a list? (len( ))
2. Which function can be used to add more than one element within an existing list? extend()
3. What is the use of type( ) function?(To know the data type of Python object)
4. A list in Python is known as ___ (sequence data type)
5. List is an ordered collection of values enclosed within ___ [ ]
6. The index value for each element of a list begins with __ ( 0 )
7. A list element or range of elements can be changed or altered by using __ ( = )
8. Which function removes all the elements from the list and retains the list ? (clear( ))
9. ___ statement is used to delete known elements from the list. (del)
10. Which function is used to delete a particular element using its index value? (pop( ))
11. ___ is the powerful feature in python related with Tuples. (Assignment)
12. Creating a Tuple with one element is called as ___ (Singleton)
13. A list or tuple can be converted as set by using ___ function (set( ) )
14. What will be the output of the given code ? [1,4,27,256]
>>>lst = [x**x for x in range(1,5)]
>>>print(lst)
TWO MARKS :-
15. What is a list of Python?
A list of Python is known as a “sequence data type” like strings. Each value of a list is called as
element.
15. Write a difference between del() and remove() function of List?
del() function is used to delete known elements whereas remove() function is used to delete
elements of a list if its index is unknown. The del function also be used to delete entire list.
16. What is set in Python?
A set is another type of collection data type. A set is a mutable and an unordered collection of
elements without duplicates. That means the elements within a set cannot be repeated.
17. How will you access the list elements in reverse order ?
Python enables reverse or negative indexing for the list elements. Thus, python lists index in
opposite order. The python set -1 as the index value for the last element in list and -2 for the
preceding element and so on. This is called as Reverse Indexing.
THREE MARKS :-
18. What are the advantages of Tuples over a list?
❖ The elements of a list are changeable whereas the elements of a tuples are unchangeable.
17
❖ The elements of a list are enclosed within square brackets. But, the elements of a tuple
are enclosed by parenthesis.
❖ Iterating tuples is faster than list.

19. Write a short note on sort().


sort( ) :
• Sorts the elements in ascending order by default.
Syntax :
List.sort(reverse=True|False, key=myFunc)
• Both arguments are optional.
• If reverse is set as True, list sorting is in descending order.
• sort( ) will affect the original list.
Example :
>>>Mylist= [‘C’,’E’,’A’,’D’,’F’,’B’] OUTPUT :
>>>Mylist.sort() [‘A’,’B’,’C’,’D’,’E’,’F’]
>>>print(Mylist)
FIVE MARKS :-
20. List out the set operations supported by Python?
1. Union (|) : It includes all elements from two or more sets.
Ex :set_A = {2,4,6,8}
set_B = {‘A’,’B’,’C’,’D’} Output :{2,4,6,8, ‘A’,’B’,’C’,’D’}
print(set_A | set_B)
2. Intersection ( &) : It includes the common
elements in two sets.
Ex :set_A = {‘A’,2,4,’D’} Output :{ ‘A’,’D’}
set_B = {‘A’,’B’,’C’,’D’}
print(set_A&set_B)
3. Difference (-) : It includes all elements that are in first set. But, not in the second set.
Ex :set_A = {‘A’,2,4,’D’}
set_B = {‘A’,’B’,’C’,’D’} Output :{2,4}
print(set_A - set_B)
4. Symmetric Difference (^) :It includes all the elements that are in two sets. But not the one that
are common to two sets.
Ex :set_A = {‘A’,2,4,’D’} Output :{ 2,4,’B’,’C’}
set_B = {‘A’,’B’,’C’,’D’}
print (set_A ^ set_B)
21. What are the different ways to insert an element in a list. Explain with suitable example.
❖ In python append(), extend() and insert() functions are used to include more elements in a
list.
18
❖ append( ) :-
➢ append() function is used to add a single element at the end of the list.
➢ Syntax
List.append(element to be added)
➢ Example
mylist=[10,20,30,40] OUTPUT:
mylist.append(50) [10,20,30,40,50]
print(mylist)
❖ extend( ) :-
➢ extend() function is used to add more than one element to an existing list.
➢ extend() function includes multiple elements at the end of the list.
➢ Syntax
List.extend(elements to be added)
OUTPUT:
➢ Example
mylist.extend([60,70,80]) [10,20,30,40,50,60,70,80]
print(mylist)
❖ insert( ) :-
➢ insert() function is used to insert an element at any position of a list.
➢ While inserting a new element in between the existing elements, the existing elements
shifts one position to the right.
➢ Syntax
List.insert(index,element)
➢ Example OUTPUT:
mylist.insert(4, 45)
[10,20,30,40,45,50,60,70,80]
print(mylist)

CHAPTER-10 (PYTHON CLASSES AND OBJECTS)


ONE MARK :-
1. Function defined inside a class called ___ .(Methods)
2. ___ is the main building block in python. (class)
3. Class members are accessed through __ operator. (. (dot) )
4. A private class variable is prefixed with ___. ( __ )
5. ___ method is used as destructor( __del__( ) )
6. By default, the variables which are defined inside the class are ___. (Public)
7. ___ are also called as instances of a class or class variable.(Object)
8. The class method have the first argument named as ___. (self)
9. ___ is a special function that is automatically executed when an object is created. (Constructor)

19
TWO MARKS :-
10. What is class?
Class is a template for the object. In python, class is the main building block. Class is defined
by using the keyword “class”.
11. What is instantiation?
The process of creating object or instance of the class is called as “Class instantiation”.
12. How will you create constructor in Python?
In Python, there is a special function called “init” which act as a constructor. It must begin and
end with double underscore.
13. What is the purpose of Destructor?
Destructor is a special method gets executed automatically when an object exit from the
scope. In Python, __del__( ) method is used as destructor.
THREE MARKS :-
14. What are class members? How do you define it ?
• Class variable and methods are together known as members of the class.
• Variables defined inside a class are called as “Class Variable”.
• Functions are called as “Methods”.
• Class is defined by using the keyword “class”
Defining a class :
class sample:
x,y=10,20
15. Explain public and private data members of a class with an example?
❖ The variables which are defined inside the class is public by default. These variable can be
accessed anywhere in the program using the dot (.) operator.
❖ A variable prefixed with double underscore becomes private in nature. These variables can be
accessed only within the class.
❖ Example:
class bankacc:
def __init__(ano,bal)
self.accno=ano
self.__balance=bal
a1=bankacc(100001,50000)
a2=bankacc(100002,48000)
In the above program, variable accno is a public variable and balance is a private variable.

CHAPTER-11 (DATABASE CONCEPTS)


ONE MARK :-
1. DBMS Stands for ___. (DataBase Management System)
2. A table is known as ___.(Relation)
20
3. Raw facts stored in a computer are called ___. (Data)
4. Each row in table represents a ___.(Record)
5. Each column in table represents a ___.(Field)
6. A row in a database table is known as a ___. (Tuple)
7. A column in a database table is known as a ___.(Attribute)
TWO MARKS :-
8. Mention few examples of a database.
1) An address book 3) A dictionary
2) A school class register 4) A salary register of employees.

9. List some examples of RDBMS.


1) SQL server 4) MariaDB
2) Oracle 5) SQ Lite
3) Mysql 6) IBM Db2
10. What is data consistency?
Data consistency means that data values are the same at all instances of a data base.
11. What is database?
❖ A database is an organized collection of data, generally stored and accessed electronically
from a computer system.
12. What is DBMS? Give example.
A Data Base Management System is a software that allows us to create, define” and
manipulate database, allowing users to store, process and analyze data easily. Eg.Dbase, Fox pro
THREE MARKS :-
13. List the advantages of DBMS.
❖ Segregation of application program.
❖ Minimal data duplication or Data Redundancy.
❖ Easy retrieval of data using the Query Language.
❖ Reduced development time and maintenance.
FIVE MARKS :-
14. Explain the characteristics of DBMS.
❖ Data stored into Tables – Data is stored into tables, created inside the database.
DBMS allows to have relationship between tables which makes the data more
meaningful and connected.
❖ Reduced Redundancy – DBMS follows normalization which divides the data in such a
way that repetition is minimum.
❖ Data Consistency – On live data, it is being continuously updated and added,
maintaining the consistency of data can become a challenge. DBMS handles it by itself.
❖ Support multiple User and Concurrent access
➢ DBMS allows multiple users to work on it at the same time and still manages to
maintain the data consistency.

21
❖ Query Language – DBMS provides users with a simple query language, using which
data can be easily fetched, inserted, deleted and updated in a database.
❖ Security – DBMS takes care of the security of data, protecting the data from
unauthorized access.
❖ DBMS supports Transactions – It allows us to handle and manage data integrity in real
world applications where multi-threading is extensively used.

CHAPTER-12 (STRUCTURED QUERY LANGUAGE – SQL)


ONE MARK :-
1. Which command provides definition for creating table structure, deleting relation and modifying relation
scheme? (DDL)
2. Which command lets to change the structure of the table? (ALTER)
3. Queries can be generated using ___. (SELECT)
4. ___ command to delete a table.(DROP)
5. DCL Stands for ___. (Data Control Language)
6. TCL Stands for ___. (Transmission Control Language)
7. Which command is used for permanently removes one or more records from database table? (DELETE)
8. Using which clause, the UPDATE command specifies the rows to be changed? (WHERE)
9. Which symbol is used to specify all the fields and rows of the table? (*)
10. Which command restores the database of the last committed state? (ROLL BACK)
11. Which command is used for saves any transaction into the database permanently? (COMMIT)
12. ___ is a programming language to access and manipulate databases. (SQL)
13. Which constraint may use relational and logical operators for condition ? (check constraint)
14. Which clause is used to sort the data in either ascending or descending order ? (ORDER BY)
15. Which clause can be used along with GROUP BY clause to place condition ? (HAVING)
TWO MARKS :-
16. Write a query that selects all students whose age is less than 18 in order wise.
SELECT * FROM student WHERE Age < 18 ORDER BY Name;
17. Differentiate Unique and Primary key constraint.
Unique Constraint Primary key constraint
❖ Many fields can be set with UNIQUE Only one field of a table can be set as
constraint. primary key.
❖ This ensures that no two rows have the This declares a field as a primary key which
same value in the specified columns. helps to uniquely identify a record.
18. Write the difference between table constraint and column constraint?
Table constraint Column constraint
It is applied to a group of one or more columns It is applied only to individual column of the
table.
Normally given at the end of the table Given along with the field name.
definition.

22
19. Which component of SQL lets insert values in tables and which lets to create a table?
❖ DML lets you to insert values in tables and DDL lets you to create a table.
20. What is the different between SQL and My SQL?
SQL MySQL
Structured Query Language is a Language used It is Relational Database Management
for accessing databases. system.
It helps to create and operate relational It uses SQL to query the databases.
databases.
THREE MARKS :-
21. Write any three DDL commands.
Data Definition Language are:
Create To create tables in the database.
Alter Alters the structure of the database.
Drop Deletes tables from database.
Truncate Removes all records from a table, also releases the space occupied by those
records.
22. Write the use of Save point command with an example.
➢ The SAVEPOINT command is used to temporarily save a transaction so that we can rollback
to the point whenever required.
➢ The different states of the table can be saved at anytime using different names and the
rollback to that state can be done using the ROLLBACK command.
SAVEPOINT savepoint _ name;
Example :
Savepoint A;
Insert into Student values(105,”Anitha”,450);
Rollback to A;
In the above example, Rollback command is used with Savepoint command to jump to a
particular savepoint location. So, the changes made using Insert command is cancelled in the above.
23. Compare DELETE,TRUNCATE and DROP command in SQL.
❖ DELETE – DELETE command deletes only the rows from the table based on the condition, if
no condition is specified, it deletes all the rows. But it does not free the space containing
the table.
❖ TRUNCATE – It deletes all the rows and free the space containing the table. But the
structure remains in the table.
❖ DROP – This command is used to remove an object from the database. If you drop a table,
we cannot get it back.
FIVE MARKS :-
24. Write the different types of constraints and their functions?
23
The different types of constraints are:
i) Unique constraint
ii) Primary Key Constraint
iii) Default Constraint
iv) Check Constraint
❖ Unique Constraint:-
➢ This constraint ensures that no two rows have the same value in the specified columns.
E.g : UNIQUE constraint applied on Admno of student table ensures that no two
students have the same admission number.
➢ The UNIQUE constraint can be applied only to fields that have also been declared as
NOTNULL.
❖ Primary Key Constraint:-
➢ This constraint declares a field as a Primary key which helps to uniquely identify a
record.
➢ It is similar to unique constraint except that only one field of a table can be set as
primary key.
➢ The primary key does not allow NULL values and therefore a field declared as primary
key must have the NOT NULL constraint.
❖ DEFAULT Constraint:-
➢ The DEFAULT constraint is used to assign a default value for the field.
➢ When no value is given for the specified field having DEFAULT constraint, automatically
the default value will be assigned to the field.
❖ 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.
❖ 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 :-
e.g : CREATE TABLE Student
(
Admno integer NOTNULL UNIQUE,
Firstnamechar(20),
Lastnamechar(20),
Gender char(1)DEFAULT = “M”, →Default constraint
Age integer (CHECK <=19), → Check constraint
Place char(10),
PRIMARY KEY( Firstname, Lastname) → Table constraint,
);

24
25. What are the components of SQL ? Write the commands in each (CH-12)
❖ SQL commands are divided into five categories.

SQL Commands

DDL Command DML Command DCL Command TCL Command DQL Command

❖ DDL (Data Definition Language) :-


➢ Data Definition Language consists of SQL statements used to define the
database structure or schema.
➢ DDL commands are used to create and modify the structure of database
objects.
➢ DDL commands are
1. CREATE – To create tables in the database.
2. ALTER - Alters the structure of the database.
3. DROP - Delete tables from database.
4. TRUNCATE – Remove all the records from the table, and also release the
space occupied by those records.
❖ DML (Data Manipulation Language) :-
➢ DML commands are used for adding(inserting), removing(deleting) and
modifying(updating) data in a database.
➢ DML commands are
1. INSERT – Inserts data into a table.
2. UPDATE – Updates the existing data within a table.
3. DELETE – Deletes all records from a table, but not the space occupied by them.
❖ DCL (Data Control Language) :-
➢ DCL commands are used to control the access of data stored in a database.
➢ It is used for controlling privileges in the database.
➢ DCL commands are
1. GRANT - Grants permission to one or more users to perform specific tasks.
2. REVOKE – Withdraws the access permission given by the GRANT statement.
❖ TCL (Transactional Control Language) :-
➢ TCL commands are used to manage transactions in the database.
➢ TCL commands are
1. COMMIT – Saves any transaction into the database permanently.
2. ROLL BACK – Restores the database to last commit state.
3. SAVE POINT – Temporarily save a transaction so that you can rollback.
❖ DQL (Data Query Language) :-
➢ DQL commands are used to query or retrieve data from a database.
1. SELECT – It displays the records from the table.
25
CHAPTER-13 (PYTHON AND CSV FILES)
ONE MARK :-
1. A CSV file is also known as a___ (FlatFile)
2. The expansion of CRLF is ___(Carriage Return and LineFeed)
3. CSV stands for___ ( Comma Separated Values)
4. CSV file values can be separated by___(comma ,)
5. How many ways to read a CSV file? (2)
6. CSV file contents can be read with the help of the method ___(CSV.reader())
7. ___ Method is used to insert list into CSV File (CSV.writer())
8. A normal CSV File created by ___(CSV.writer() )
9. csv.reader() and csv.writer() can be work with ___(List and Tuples)
10. The default file opening mode is ___ (read and text)
11. ___ is used for removing whitespaces after the delimiter. (skipinitialspace)
12. ___ method is used to write all the data at once. (writerows( ))
TWO MARKS :-
13. What is CSV File?
A CSV file is human readable text file where each line has a number of fields, separated by
comma or some other delimiter. A CSV File can also have called Flat-file.
14. What is the uses of CSV File?
CSV is a simple file format used to store tabular data, such as a spreadsheet or database. Since
they are plain text, They are easier to import into a spreadsheet or another storage database
regardless of the specific software.
15. What is the uses of Close method?
Closing a file will free up the resources that were tied with the file and is done using Python
close() method.
16. Mention the two ways to read a CSV file using Python.
There are two ways to read a CSV file.
1. Using csv.reader() function
2. Using DictReader class.
THREE MARKS :-
17. What is the difference between write mode and append mode?
Write Append
The ‘w’ Write mode create a new file .if the This is ‘a’ append mode is used to add the
file already exist overwrite it. data at the end of file if the file already exist
otherwise create it.
18. What is dialect?
A dialect is a class of csv module which helps to define parameters for reading and writing
CSV. It allows to create, store, and re-use various formatting parameters for data.
26
19. Write a note on open() function of python. What is the difference between the two methods.
• Python has a built-in function open() to open a file.
• This function returns a file object, which is used to read or modify the file.
• Specifying the file mode is important, while opening a file.
• Example :
f=open(“text.csv”)
……
f.close()
• If an exception occurs, the code exits without closing the file.
• So, the above method is not entirely safe.
• The best way to do this using the “with” statement.
• Example:
with open(“test.csv”) as f:
• This ensures that the file is closed when the block inside with is exited.
• Closing a file will free up the resources that were tie with the file.
FIVE MARKS
20. Differentiate Excel File and CSV file.
Excel CSV
Excel is a binary file that holds information about CSV format is plain text format with a series of
all the worksheets in a file including both content values separated by comma
and formatting
Excel file can only create and read with specific CSV file can be opened with any text editor in
application windows like notepad ,open office, Ms-Excel,
etc.,
Excel is a spreadsheet the saves files into its own CSV is a format for saving tabular information
proprietary format viz. xls or xlsx in to delimited text file with extention.csv
Excel Consume more memory while importing Importing CSV files can be much faster, and its
data also consumes less memory.

CHAPTER-14 (IMPORTING C++ PROGRAMS IN PYTHON)


ONE MARK :-
1. ___ is not a scripting language (HTML)
2. ___ is a glue language. (Python)
3. Expansion of API is___(Application Programming Interface)
4. A framework for interfacing Python and C++is___(Boost)
5. ___ can be used for processing text, numbers,images and scientific data(Python)

27
6. Importing C++ program in a Python program is called___(wrapping)
7. The operator used to access the python function using modules is ___ (.)
8. The command to clear the command window is ___(Cls)
9. Which execute the C++ compiling command ?(os.system())
10. ___ provides a way of using operating system dependent functionality. (os module)
11. ___ is a built-in variable which evaluates the name of the current module. ( __name__ )
12. Which module helps you to parse command line options and arguments. (getopt)
TWO MARKS :-
13. Write the expansion of (i) SWIG (ii) MinGw
1. SWIG - Simplified Wrapper Interface Generator.
2. MinGW - Minimalist GNU for Windows.
14. What is meant by scripting Language?
A scripting language is a programming language designed for integrating and
communicating with other programming languages.
Ex: JavaScript, VBScript, PHP, Perl, Python, Ruby, ASP and Tcl.
15. What is meant by g++?
g++ is a program that calls GCC (GNU C Compiler) and automatically links the
required C++ library files to the object code.
THREE MARKS :-
16. Differentiate compiler and Interpreter.
Compiler Interpreter
The compiler takes a program as a whole and Interpreter translates a program statement by
translates it. statement.
It generates intermediate object code. It does not produce any intermediate object
code.
Faster but requires more memory Slower and requires less memory
C,C++ use Compiler Python ,Ruby and PHP use interpreter
17. Differentiate Python and C++.
Python C++
Interpreted language Compiled Language
Dynamic typed language Statically typed language
Data type is not required while declaring Data type is required while declaring
variable variable
It can act both scripting and general purpose It is a general purpose language
language

28
18. What is module ? how to import module in Python?
Modules refer to a file containing Python statements and definitions. We can import the
definitions inside a module to another module. We use the import keyword to do this. To import our
previously defined module factorial we type the following in the Python prompt.
>>> import factorial
19. What is MINGW? What is its use?
• MINGW refers to Minimalist GNU for windows.
• MINGW contains set of runtime header files, used in compiling and linking the code of
C,C++, and FORTRAN to be run on Windows.
• This interface allows to compile and execute C++ program dynamically through python
program using g++.
FIVE MARKS :-
20. What is the purpose of sys,os,getopt module in Python.
sys module :-
• This module provides access to some variables used by the interpreter and to
functions that interact strongly with the interpreter.
• To use sys.argv, first you have to import sys.
• Sys.argv is the list of command-line arguments passed to the python program.
• The first argument sys.argv[0], is always the name of the program itself.
• The second argument sys.argv[1], is the argument you pass to the program.
• Example :
main(sys.argv[1])
os module :-
• Os module provides a way of using operating system dependent functionality.
Example :
• os.system( ) – This function executes the c++ compiling command in the shell.
Syntax :
os.system(‘g++’ + <var1> + ‘-mode’ + <var2>)
g++ - compiler to compile c++ program.
var1 – name of the c++ file
mode – Specify input or output mode.
var2 - name of the executable file without extension.
Example :
os.system(‘g++’+’sample.cpp’+’-o’+’sample’)
Here g++ compiler compiles the file sample.cpp and send output to sample.
getopt module :-
• getopt module helps to parse command-line options and arguments.
• getopt method enables command-line parsing i.e it parses sys.argv
29
and this function returns two different list or arrays opts and args.
Syntax :
• <opts>,<args>=getopt.getopt(argv,options,[long-options])
argv - This is the argument list of values to be parsed.
options – This is the string of options or modes (like ‘i' or ‘o’) followed by colon(:).
L-options – Argument of long style options should be followed by an equal sign(=)
opts – opts contains list of splitted strings like mode and path.
args – args contains any string if it not splitted because of wrong path or mode.
Example :
Opts,args = getopt.getopt(argv,”i:”,[‘ifile=’])

CHAPTER-15 (DATA MANIPULATION THROUGH SQL)


ONE MARK :-
1. SQLite fall under which database system? (Relational Database System)
2. The most commonly used statement in SQL is ___(SELECT)
3. Which SQL statement accessing data from database?(SELECT)
4. ___ has a native library for SQLite. (Python)
5. ___ method returns the next number of rows of the result set. (fetchmany())
6. ___values are not counted using count() command.(NULL)
7. To print all elements in new lines print() function uses ___ parameter. (sep)
8. ___ is an organized collection of data.(database)
9. ___ is an aggregate function which returns the number of rows in a table satisfying the given
criteria. (count( ))
10. ___ is a control structure to traverse over the records in a database. (cursor)
11. Which aggregate function returns the largest value of the selected column ? (max( ))
TWO MARKS :-
12. Which method is used to connect a database? Give an example.
• Create a connection using connect( ) method and pass the name of the database File.
• connect( ) method is used to connect SQLite database.
Example: import sqlite3
connection=sqlite3.connect(“Academy.db”)
cursor=connection.cursor
13. What is the advantage of declaring a column as “INTEGER PRIMARY KEY”.
If a column of a table is declared to be an INTEGER PRIMARY KEY, then whenever a
NULL will be used as an input for this column, the NULL will be automatically
converted into and integer which will one larger than the highest value so far used in
that column.
THREE MARKS :-
14. What is SQLite? What is its advantage?

30
• SQLite is a simple relational database system, which saves its data in regular data files
or even in the internal memory of the computer.
• It is designed to be embedded in applications, instead of using a separate database
server program such as MySQL or Oracle.
15. Write down fetchone( ), fetchmany( ), fetchall( ) commands.
cursor.fetchall( ) : fetchall( ) method is to fetch all rows from the database table.
cursor.fetchone() : fetchone() method returns the next row of a query result set or none
in case there is no row left.
cursor.fetchmany() : fetchmany( ) method that returns the next number of rows(n) of the
result set.
FIVE MARKS :-
16. Write in brief about SQLite and the steps used to use it.
• SQLite is a simple relational database system, which saves its data in regular
data files or even in the internal memory of the computer.
• It is designed to be embedded in applications, instead of using a separate
database server program such as MySQL or Oracle.
• SQLite is fast, rigorously tested, and flexible, making it easier to work.
• Python has a native library for SQLite.
To use SQLite
Step 1: import sqlite3
Step 2: Create a connection using connect() method and pass the name of the database file.
Step 3: Set the cursor object cursor=connection.cursor()
➢ Connecting to a database in step2 means passing the name of the database to be accessed. If
the database already exists, the connection will open the same. Otherwise, Python will open
a new database file with the specified name.
➢ Cursor in step 3: is a control structure used to traverse and fetch the records of the database.
➢ Cursor has a major role in working with Python. All the commands will be executed using
cursor object only.
Example:
import sqlite3
connection=sqlite3.connect(“Academy.db”)
cursor=connection.cursor( )

CHAPTER-16 (DATA VISUALIZATION USING PYPLOT)


ONE MARK
1. ___ is a python package used for 2D graphics.(matplotlib.pip)
2. An ___is the representation of information in a graphic format.(Infographics)
3. ___ is the most popular data visualization library in Python.(Matplotlib)
4. To install matplotlib, Python –m pip install –U pip function will be typed in your command
31
prompt. What does “U” represents? (Upgrading pip to the latest version)
5. The plot method on series and Data Frame is just a simple wrapper around.plt.plot()
6. ___ plots are often used for checking randomness in time series. (Autocorrelation)
7. ___ is a collection of resources assembled to create a single unified visual display. (Dashboard)
8. ___ is a management software for installing python packages. (pip)
9. Which plot shows the relationship between a numerical variable and categorical variable ?
(Barchart)
TWO MARKS :-
10. What is meant by infographics?
An infographic (information graphic) is the representation of information in a graphic format.
11. What is meant by scatter plot?
• A scatter plot is a type of plot that shows the data as a collection of points.
• The position of a point depends on its two-dimensional value, where each value is a position on
either the horizontal or vertical dimension
12. Define Data visualization
• Data visualization is the graphical representation of information and data.
• The objective of Data Visualization is to communicate information visually to users.
13. List the general types of data visualization.
• Charts • Maps
• Tables • Infographics
• Graphs • Dashboards.
14. List the types of Visualizations in Matplotlib.
• Line Plot • Box Plot
• Scatter Plot • Bar Chart and
• Histogram • Pie Chart
15. How will you install Matplotlib ?
• To install Matplotlib, type the following in the command prompt.
• Python –m pip install –U matplotlib
• This command will download matplotlib from the source library.
THREE MARKS :-
16. Explain the purpose of the following Functions.
a.plt.xlable() b. plt.ylabel() c.plt.title() d. plt.legend() e.plt.show()
a. plt.xlabel() – refers label for x axis.
b. plt.ylabel() – refers label for y axis.
c. plt.title() – denote title to the graph.
d. plt.legend()- invoke the default legend with plt.
e. plt.show( )- display the plot.
32
17. List out the uses of Data Visualization.
• Data visualization help users to analyze and interpret the data easily.
• It makes complex data understandable and usable.
• Various Charts in Data Visualization helps to show relationship in the data for one or
more variables.
18. Write the coding for the following
a. To check if PIP is Installed in your PC.
b. To check the version of PIP installed in your PC
c. To list the packages in matplotlib.

a. python –m pip install –U pip


b. c:\users\your name\Local\Programs\Python\Python 36 – 32\Scripts>pip –version
c. C:\Users\your Name\Local\Program\Python\Python 36-32\Scripts>pip list
FIVE MARKS :-
19. Write the key difference between Histogram and Bar Graph
HISTOGRAM BAR GRAPH
Histogram refers to a graphical representation; A bar graph is a pictorial representation of
that displays data by way of bars to show data that uses bars to compare different
frequency of numerical data. categories of data.
A histogram represents the frequency A bar graph is a diagrammatic comparison of
distribution of continuous variables. discrete variables.
Histogram presents numerical data. Bar gap shows categorical data.
The histogram is drawn in such a way that There is a proper spacing between bars in a
there is no gap between the bars bar graph that indicates discontinuity.
Items of the histogram are numbers, which are Bar graph items are considered as individual
categorized together, to represent ranges of entities.
data.
The width of rectangular blocks in a histogram The width of the bars in a bar graph is always
may or may not be same same.

33
SYNTAXES WITH EXAMPLES
1. print() function

print(“String”) print(“Welcome to python”)


print(variable) print(a)
print(“String”,variable) print(“The sum =”,c)
print(“String1”,var1,”String2”,var2,”String3”……) print(“The sum of “,a,”and”,y,”is”,z)

2. input() function

Variable = input(“Prompt String”) city=input(“Enter your city “)

3. Conditional operator (if..else)

Variable = [on_true] if [test exp] else [on_false] min = 50 if 49<50 else 70

4. Simple if statement

if <condition>: if age>=18:
statements_block print(“Eligible for voting”)

5. if..else statement

if <condition>: if a%2==0:
statements_block1 print(“Even number”)
else: else:
statements_block2 print(“Odd number”)

6. Nested if..elif..else statement

if <condition_1>: if avg>=80:
statements_block1 print(“Grade A”)
elif<condition_2> elif avg>=70 and avg<80:
statements_block2 print(“Grade B”)
else: elif avg>=60 and avg<70:
statements_block n print(“Grade C”)
elif avg>=50 and avg<60:
print(“Grade D”)
else:
print(Grade E”)

34
7. while loop

while <condition>: while (i<=15):


statements_block1 print(i)
[else: i=i+1
statements_block2]

8. range

range(start,stop,[step]) range(2,30,2)
9. for loop

for var in sequence: for i in range(2,10,2):


statements_block1 print(i)
[else:
statements_block2]

10. User defined function

def<function_name ([parameter1,parameter2…]>: defarea(w,h):


statements_block print(“Area”)
return <expression/None> return w*h

11. Lambda function

lambda [argument(s)]:expression sum=lambda arg1,arg2:arg1+arg2

12. List

List_variable=[E1,E2,E3…En] Mylist=[“Welcome”,3.14,10,[2,4,6]]

13. Tuple

Tuple_Name = (E1,E2,E3…En) Mytup=(2,4,6)


Tuple_Name = E1,E2,E3…En Mytup=2,4,6,8,10

14. Sets

set_variable = {E1,E2,E3…En} Myset={2,4,6,8,10}

15. Defining Classes

class class_name: class sample:


statement_1 x,y=10,20
35
statement_2
…………...
statement_n

16. CREATE TABLE Command

Create table<table name> Create table student


(<column name><data type>[<size>], (Admnointeger,Name char(20),
<column name><data type>[<size>]…..); Gender char(1),Age integer, place char(10));

17. INSERT Command

Insert into<table name> [column list] Insert into student(Admno,Name,Age,place)


values (values); values (1001,’JAI’,’M’,18,’Madurai’);

18. DELETE Command

Delete from table-name where condition; Delete from student whereAdmno=101;

19. UPDATE Command

Update<table-name>set column-name1=value1, Update student set Age=20 where


column-name2=value2… where condition; place=”Chennai”;

20. ALTER Command

Alter table <table-name>add<column name><data Alter table student add Address char;
type><size>;

21. Truncate and Drop Table Command

Truncate table table-name; Truncate table student;


Drop table table-name; Drop table student;

22. SELECT Command

Select <column-list>from <table-name>; Select Admno,Namefromstudent;

36

You might also like