Terminal2 New 1
Terminal2 New 1
Syntax
if <condition-1>:
statements-block 1
elif <condition-2>:
statements-block 2
else:
Eg statements-block n
if a>0:
print (“positive”)
elif a<0:
print (“negative”)
else:
print (“zero”)
13. Sys moduleThis module provides access to builtin variables used by the interpreter. Eg: argv
sys.argv is the list of command-line arguments passed to the Python program.
argv contains all the items that come via command-line input To use sys.argv,
import sys
sys.argv[0] contains the name of the python program sys.argv[1]is
the next argument passed to the program. main(sys.argv[1])
argv[1] c++ file name along with the path argv[0] contains the Python program
need not be passed because by default main contains python program
OS Module
provides a way of using operating system dependent functionality. It allows to interface with the
Windows operating system os.system():Execute the C++ compiling command in the shell g++
compiler is used to compile c++ program
syntax os.system(‘g++’+<variable_name1>+‘-<mode>’+<variable_name2>)
os.system- system() function defined in os module to interact with the windows operating system
g++ :- compiler to compile C++ program in Windows Operating system.
variable_name1:-Name of the C++ file along with the path without extension in string format
mode:-To specify input or output mode. Eg o prefixed with hyphen.
variable_name2:-Name of the executable file without extension in string format
eg: os.system('g++ '+cpp_file + '-o '+ exe_file) ‘+to concatenate all the string as a single string
getopt module helps to parse command-line arguments.
getopt.getopt() parses command-line options and parameter list.
syntax
<opts>,<args>=getopt.getopt(argv,options,[long_options])
opts contains list of splitted strings like mode and path
args contains error string, it will be empty if no error / argv This is the argument list to be parsed
options - it is a string to denote the mode (like ‘i’ or ‘o’)followed by a colon (:)
long_options –it is alist of strings.contain c++ file name with path and mode followed by an equal
sign ('=').
Eg: opts,args=getopt.getopt(argv,"i:",['ifile='])
14. 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 within 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.
advantages
fast, rigorously tested, flexible and easy to work.
Step 1 import sqlite3
Step 2 create a connection using connect () method and pass the name of the database File
If the database already exists the connection will open .Otherwise, Python will
open a new database file with the specified name
Step 3 Set the cursor object cursor = connection. cursor ()
Cursor is a control structure used to traverse and fetch the records of the database.
All the commands will be executed using cursor object only.
sql_comm = "SQL statement"
execute() is used to execute the command and use the cursor method and pass the required sql
command as a parameter.
Many number of commands can be stored and can be executed one after other.
commit()- command is used to save the changes
close()-command is used to close the "Table connection".
15. Differentiate DBMS and RDBMS.
Basis of comparison DBMS RDBMS
Expansion Database Management System Relational DataBase Management System
Data storage Navigational model data by Relational model (in tables). ie data in tables as row
linked records and column
Data redundancy Exhibit Not Present
Normalization Not performed RDBMS uses normalization to reduce redundancy
Data Access Consumes more time Faster, compared toDBMS.
Keys and Index Does not use. used to establish relationship. Keys are used in
RDBMS.
Transaction Inefficient, Error prone and Efficient and secure.
management insecure.
Distributed Databases Not supported Supported by RDBMS.
Example Dbase, FoxPro. SQL server, Oracle, mysql, MariaDB, SQLite.
15.What are called Parameters and write a note on Parameter without Type & Parameter with Type
Parameters are the variables in a function definition
arguments are the values which are passed to function definition.
Parameter without Type
Example:
(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)
require-precondition ,return-post condition.
Here data type is not mentioned . Some language compiler solves this type inference problem
algorithmically,
Parameter with Type
(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)
in type annotations the parentheses are mandatory.
explicitly annotating the types help with debugging the type errors
16. Discuss about Linear search algorithm.
• Linear search also called sequential searchis 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 isexhausted.
• 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.
• 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.
EX1: input: values[]={10,20,30,40,50}
Target=30
output=2
ex2: target=35 output=-1 if not found
excel files can only be read by applications and CSV can be opened with any text editor eg
can only be written in the same way. notepad,MS Excel, OpenOffice,etc.
Excel save the file with extension .xls or xlsx CSV save the file with extension .csv
consumes more memory while importing data consumes less memory and importing is faster
20. Explain the various buttons in a matplotlibwindow.
Home Button:
help once you have begun navigating your chart.
return back to the original view,
Forward/Back buttons:
click these to move back to the previous point , or
forward again.
Pan Axis:
allows you to click it, and then click and drag your graph around.
Zoom: click and drag a square to zoom into specifically. Zooming in require a left click and drag. zoom out
with a right click and drag.
Configure Subplots: allow to configure variousspacing options with your figure and plot.
Save Figure:allow you to save your figurein various forms.
21. Features of Python over C++
• Python uses Automatic Garbage Collection whereas C++ does not.
• C++ is a statically typed language, while Python is a dynamically typed language.
• Python runs through an interpreter, while C++ is pre-compiled.
• Python code 5 to 10 times shorter than that written in C++.
• In Python, there is no need to declare types explicitly where as it should be done in C++
• In python function return multiple values Whereas in C++ function return only one value
22. Tabulate the different mode with its meaning.
'r' →Open a file for reading. (default)
'w'→ Open a file for writing. Creates a new file if it does not exist or truncates the file if it exists.
'x' →Open a file for exclusive creation. If the file already exists, the operation fails.
'a'→ Open for appending at the end of the file without truncating it. Creates a new file if it does not exist.
't'→ Open in text mode. (default)
'b'→ Open in binary mode.
'+' →Open a file for updating (reading and writing)
23. CONSTRUCTOR AND DESTRUCTOR
Constructor is the special function .
It is automatically executed when an object of a class is created.
“init” which act as a Constructor.
It must begin and end with double underscore.
It can be defined with or without arguments.
This method is used to initialize the class variables.