Uploaded by kiranlovely2003

final record

advertisement
INDUSTRIAL TRAINING REPORT
A report submitted in partial fulfilment of the requirements of the award of degree of
DIPLOMA IN COMPUTER ENGINEERING
Submitted by
ARBIND TUSHAR PATHAK
(20280-CM-002)
UNDER THE GUIDENCE
OF
Dr.N.PENCHALIAH,Ph.D
DEPARTMENT OF COMPUTER ENGINEERING
AUDISANKARA COLLEGE OF ENGINEERING & TECHNOLOGY
2nd SHIFT POLYTECHNIC, GUDUR.
(Approved By ACITE, SBTET VIJYAWADA)
NH-5 ROAD, GUDUR-524101.
2020-2023
DEPARTMENT OF COMPUTER ENGINEERING
AUDISANKARA COLLEGE OF ENGINEERING &TECHNOLOGY
CERTIFICATE
This is to certify that the “INDUSTRIAL TRAINING REPORT”submitted
by ARBIND TUSHAR PATHAK( 2 0 2 8 0 - C M - 0 0 2 ) is a bonafide record
of work done by him and submitted during 2021-2022 academic year, in partial
fulfilment of the requirements for the award of the degree of
DIPLOMA IN COMPUTER ENGINEERING.
Signature of the Guide
( Dr. N PENCHALAIAH ,Ph.D)
Head of the Department
Dr.N.PENCHALAIAH,Ph.D
PROFESOR&H.O.D
2
STUDENT DATA MANAGEMENT SYSTEM
Submitted by
ARBIND TUSHAR PATHAK
(20280-CM-002)
Under the guidance of
Dr. N PENCHALAIAH, Ph.D
DEPARTMENT OF COMPUTER ENGINEERING
AUDISANKARA COLLEGE OF ENGINEERING&TECHNOLOGY
2nd SHIFT POLYTECHNIC, GUDUR,
(Approved By ACITE, SBTET VIJYAWADA)
NH-5 ROAD, GUDUR-524101.
2020-2023
3
DECLARATION
We hereby declare that the INDUSTRIAL TRAINING REPORT titled
“STUDENT MANAGEMENT SYSTEM" is Bonafied work carried out by us under
guidance of project team at Aacharaya .Further I declare that this report has not
previously formed the basis of award of any associate ship or other similar degrees or
diplomas, has not been submitted anywhere else.
ARBIND TUSHAR PATHAK
20280-CM-002
4
ACKNOWLEDGEMENT
I Consider it our privilege to express our gratitude to all those who guided and
inspired us in the completion of this Project. We express our sincere thanks to our beloved
Chairman Dr.Vanki. Penchalaiah, Ph.d for providing support and stimulating environment
for developing the project.
I am highly indebted to Director Dr.A.Mohan Garu for the facilities provided to
accomplish this internship.
I would like to Thank our principal Dr.N.Penchalaiah ,Ph.D for his constructive criticism
throughout my internship
I would like to Thank our Project Guide Dr. N.Penchalaiah Ph.D for his help throughout
my internship.
I would like to Thank our HOD Ms.K.Nishitha ,M.TECH for his constructive criticism
throughout my internship.
I would like to Thank the internship coordinator and Project manager Dr.G.Rajesh sir for
his support and advice to complete internship and project in Aacharaya.
I feel great to Thank all the department Teaching & Non-Teaching shaff who helped us
and created interest in us to work day and night for the project
I would like to thank my family and friends who supported me throughout this journey for
completing the industrial training
ARBIND TUSHAR PATHAK
20280-cm-002
5
STUDENT MANAGEMENT SYSTEM
ABSTRACT
Name: ARBIND TUSHAR PATHAK
PinNo:20280-CM-002
Mail : arbindtusharpathak@gmail.com
Branch : CME
Student Management System is software which is helpful for students as
well as the school authorities. In the current system all the activities are
done manually. It is very time consuming and costly. Our Student
Management System deals with the various activities related to the
students .
In the Software we can register as a user and user has of two types,
student and administrator. Administrator has the power to add new user
and can edit and delete a user.
A student can register as user and can add edit and delete his profile. The
administrator can add edit and delete data for the student. It reduces the
work for people and makes it easy to maintain the student data a one
place.
6
INDEX
TITLE
Page No.
1. Origin of python……………………………………………………...08
2. What is python……………………………………………………….08
3. Features of python……………………………………………………09
4. Python indentation &comments ……………………………………10
5. Keywords and identifiers………………………………………..……11
6. Python data types…………………………………………………….12
7. data structures………………………………………………………..14
8. Operators……………………………………………………………..16
9. Functions and arguments……………………………………………..17
10.Control statements……………………………………………………19
11.Looping……………………………………………………………….20
12.File handling………………………………………………………….21
13.OOPS concepts……………………………………………………….23
14.Modules and packages………………………………………………..27
15.Exception handling in python………………………………………...31
16.Project – Student management system ………………………………34
17. Uses of python………………………………………………….........41
18.Conclusion……………………………………………………………42
7
ORIGIN OF PYTHON
Python was developed by Guido van Rossum in the late eighties and early nineties
at the National Research Institute for Mathematics and Computer Science in the
Netherlands.

Python is derived from many other languages, including ABC, Modula-3, C,
C++,Algol-68, Small Talk, and Unix shell and other scripting languages.

Python is copyrighted. Like Perl, Python source code is now available under the
GNU General Public License (GPL).

Python is now maintained by a core development team at the institute, although
Guido van Rossum still holds a vital role in directing its progress.

Python 1.0 was released in November 1994. In 2000, Python 2.0 was released.

Python 2.7.11 is the latest edition of Python 2.

Meanwhile, Python 3.0 was released in 2008. Python 3 is not backward
compatible with Python 2.

The emphasis in Python 3 had been on the removal of duplicate programming
constructs and modules so that "There should be one -and preferably only one -obvious way to do it." Python 3.5.1 is the latest version of Python3.
WHAT IS PYTHON






Python is a powerful ,open-source ,high-level &popular programming language.
Used for web development, scientific & mathematical application development
etc.
Provides excellent library support and has a large developer community.
Provides easy integration with web services &GUI-based desktop applications.
Used by most of the companies such as YouTube, Instagram, Pinterest etc.
Extensively used in data science and in for developing Machine learning
projects.
8
FEATURES OF PYTHON
 Easy-to-learn: Python has few keywords, simple structure, and a clearly defined
syntax. This allows a student to pick up the language quickly.
 Easy-to-read: Python code is more clearly defined and visible to the eyes.
 Easy-to-maintain: Python's source code is fairly easy-to-maintain.
 A broad standard library: Python's bulk of the library is very portable and cross
platform compatible on UNIX, Windows, and Macintosh.
 Interactive Mode: Python has support for an interactive mode, which allows
interactive testing and debugging of snippets of code.
 Portable: Python can run on a wide variety of hardware platforms and has the same
interface on all platforms.
 Extendable: You can add low-level modules to the Python interpreter. These
modules enable programmers to add to or customize their tools to be more
efficient.
 Databases: Python provides interfaces to all major commercial databases.
 GUI Programming: Python supports GUI applications that can be created and
ported to many system calls, libraries and windows systems, such as Windows
MFC, Macintosh, and the X Window system of Unix.
 Scalable: Python provides a better structure and support for large programs than
shell scripting. Apart from the above-mentioned features, Python has a big list of
good features. A few are listed below It supports functional and structured programming methods as well as OOP.
 It can be used as a scripting language or can be compiled to byte-code for building
large applications.
 It provides very high-level dynamic data types and supports dynamic type
checking.
 It supports automatic garbage collection.
 It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
 Compatible with a variety of platforms including Windows, Mac, Linux, Raspberry Pi,
and others
 Uses a simple syntax comparable to the English language that lets developers use fewer
lines than other programming languages
 Operates on an interpreter system that allows code to be executed immediately, fasttracking prototyping
 Can be handled in a procedural, object-orientated, or functional way
9
PYTHON INDENTATION &COMMENTS
Python Indentation:
Python indentation refers to adding white space before a statement to a particular
block of code. In another word, all the statements with the same space to the right,
belong to the same code block.
Python Comments:
Comments in Python are the lines in the code that are ignored by the interpreter
during the execution of the program. Comments enhance the readability of the code
and help the programmers to understand the code very carefully. There are three
types of comments in Python –
•
Single line Comments
•
Multiline Comments
•
Docstring Comments
10
KEYWORDS AND IDENTIFIERS
Keywords:
Keywords are some predefined and reserved words in python that have special
meanings. Keywords are used to define the syntax of the coding. The keyword cannot
be used as an identifier, function, and variable name. All the keywords in python are
written in lower case except True and False. There are 33 keywords in Python 3.7
let’s go through all of them one by one.
List of all keywords Python
and,as,assert,break,class,continue,def,del,elif,else,except,False,finally,for,from,global
,if,import,in,is,lambda,None,nonlocal,not,or,pass,raise, return, True ,try, while ,with
,yield.
IDENTIFIERS :
Identifier is a name used to identify a variable, function, class, module, etc. The
identifier is a combination of character digits and underscore. The identifier should
start with a character or Underscore then use a digit. The characters are A-Z or a-z, an
Underscore ( _ ) , and digit (0-9). we should not use special characters ( #, @, $, %, !
) in identifiers.
Examples of valid identifiers:
var1
_var1
11
DATA TYPES
Data types are the classification or categorization of data items. It represents the
kind of value that tells what operations can be performed on a particular data. Since
everything is an object in Python programming, data types are actually classes and
variables are instance (object) of these classes.
Following are the standard or built-in data type of Python:
Numeric
Sequence Type
Boolean
Set
Dictionary
12
Numeric:
In Python, numeric data type represent the data which has numeric value. Numeric
value can be integer, floating number or even complex numbers. These values are
defined as int, float and complex class in Python.

Integers – This value is represented by int class. It contains positive or negative
whole numbers (without fraction or decimal). In Python there is no limit to how long
an integer value can be.

Float – This value is represented by float class. It is a real number with floating
point representation

Complex Numbers – Complex number is represented by complex class. It is
specified as (real part) + (imaginary part)j. For example – 2+3j
Sequence Type:
In Python, sequence is the ordered collection of similar or different data types.
Sequences allows to store multiple values in an organized and efficient fashion. There
are several sequence types in Python –
String
List
Tuple
Boolean:
Data type with one of the two built-in values, True or False. Boolean objects that
are equal to True are truthy (true), and those equal to False are falsy (false). But nonBoolean objects can be evaluated in Boolean context as well and determined to be
true or false. It is denoted by the class bool.
Set:
In Python, Set is an unordered collection of data type that is iterable, mutable and
has no duplicate elements. The order of elements in a set is undefined though it may
consist of various elements.
Dictionary:
Dictionary in Python is an unordered collection of data values, used to store data
values like a map, which unlike other Data Types that hold only single value as an
element, Dictionary holds key:value pair. Key-value is provided in the dictionary to
make it more optimized. Each key-value pair in a Dictionary is separated by a colon:,
whereas each key is separated by a ‘comma’.
13
DATA STRUCTURES
The basic Python data structures in Python include list, set, tuples, and dictionary.
Each of the data structures is unique in its own way. Data structures are “containers”
that organize and group data according to type.
The data structures differ based on mutability and order. Mutability refers to the
ability to change an object after its creation. Mutable objects can be modified, added,
or deleted after they’ve been created, while immutable objects cannot be modified
after their creation. Order, in this context, relates to whether the position of an
element can be used to access the element.
Python Data Structures – Lists
A list is defined as an ordered collection of items, and it is one of the essential data
structures when using Python to create a project. The term “ordered collections”
means that each item in a list comes with an order that uniquely identifies them. The
order of elements is an inherent characteristic that remains constant throughout the
life of the list.
Since everything in Python is considered an object, creating a list is essentially
creating a Python object of a specific type. When creating a list, all the items in the
list should be put in square brackets and separated by commas to let Python know
that a list has been created. A sample list can be written as follows:
List_A = [item 1, item 2, item 3….., item n]
Lists can be nested
A list can be nested, which means that it can contain any type of object. It can
include another list or a sublist – which can subsequently contain other sublists itself.
There is no limit to the depth with which lists can be nested. An example of a nested
list is as follows:
List_A = [item 1, list_B, item 3….., item n]
Lists are mutable
Lists created in Python qualify to be mutable because they can be altered even after
being created. A user can search, add, shift, move, and delete elements from a list at
their own will. When replacing elements in a list, the number of elements added does
not need to be equal to the number of elements, and Python will adjust itself as
needed.
It also allows you to replace a single element in a list with multiple elements.
Mutability also enables the user to input additional elements into the list without
making any replacements.
14
Python Data Structures – Tuples
A tuple is a built-in data structure in Python that is an ordered collection of objects.
Unlike lists, tuples come with limited functionality.
The primary differing characteristic between lists and tuples is mutability. Lists are
mutable, whereas tuples are immutable. Tuples cannot be modified, added, or deleted
once they’ve been created. Lists are defined by using parentheses to enclose the
elements, which are separated by commas.
The use of parentheses in creating tuples is optional, but they are recommended to
distinguish between the start and end of the tuple. A sample tuple is written as
follows:
tuple_A = (item 1, item 2, item 3,…, item n)
Empty and One Single Item Tuple
When writing a tuple with only a single element, the coder must use a comma after
the item. This is done to enable Python to differentiate between the tuple and the
parentheses surrounding the object in the equation. A tuple with a single item can be
expressed as follows:
some_tuple = (item 1, )
If the tuple is empty, the user should include an empty pair of parentheses as
follows:Empty_tuple= ( )
Why Tuples are Preferred over Lists
Tuples are preferred when the user does not want the data to be modified.
Sometimes, the user can create an object that is intended to remain intact during its
lifetime. Tuples are immutable, so they can be used to prevent accidental addition,
modification, or removal of data.
Also, tuples use less memory, and they make program execution faster than using
lists. Lists are slower than tuples because every time a new execution is done with
lists, new objects are created, and the objects are not interpreted just once. Tuples are
identified by Python as one immutable object. Hence, they are built as one single
entity.
Python Data Structures – Sets
A set is defined as a unique collection of unique elements that do not follow a
specific order. Sets are used when the existence of an object in a collection of objects
is more important than the number of times it appears or the order of the objects.
Unlike tuples, sets are mutable – they can be modified, added, replaced, or removed.
A sample set can be represented as follows:
set_a = {“item 1”, “item 2”, “item 3”,….., “item n”}
One of the ways that sets are used is when checking whether or not some elements
are contained in a set or not.
15
OPERATORS
Python Operators in general are used to perform operations on values and
variables. These are standard symbols used for the purpose of logical and arithmetic
operations. In this article, we will look into different types of Python operators.
OPERATORS: Are the special symbols. Eg- + , * , /, etc.
OPERAND: It is the value on which the operator is applied.
Python Operators:
•Arithmetic operators.
Arithmetic operators are used to performing mathematical operations like addition,
subtraction, multiplication, and division.
•Comparison operators.
Comparison of Relational operators compares the values. It either returns True or
False according to the condition.Logical Operators
•Logical operators
Logical operators perform Logical AND, Logical OR, and Logical NOT operations.
It is used to combine conditional statements.Bitwise Operators
•Bitwise operators.
Bitwise operators act on bits and perform the bit-by-bit operations. These are used to
operate on binary numbers.
Assignment Operators
Assignment operators are used to assign values to the variables.
•Identity operators.
is and is not are the identity operators both are used to check if two values are located
on the same part of the memory
•Assignment operators.
Assignment Operators are used to assigning values to variables.
•Membership operators.
Python offers two membership operators to check or validate the membership of a
value. It tests for membership in a sequence, such as strings, lists, or tuples.
Precedence and Associativity of Operators
Precedence and Associativity of Operators: Operator precedence and associativity
determine the priorities of the operator.
Operator Precedence:This is used in an expression with more than one operator with
different precedence to determine which operation to perform first.
Operator Associativity:If an expression contains two or more operators with the same
precedence then Operator Associativity is used to determine. It can either be Left to Right or
from Right to Left.
16
FUNCTIONS AND ARGUMENTS
Function is a block of statements that return the specific task.
The idea is to put some commonly or repeatedly done tasks together and make a
function so that instead of writing the same code again and again for different inputs,
we can do the function calls to reuse code contained in it over and over again.
Syntax: Python Functions
Creating a Python Function:
We can create a Python function using the def keyword.
Calling a Python Function:
After creating a function we can call it by using the name of the function followed
by parenthesis containing parameters of that particular function.
Defining and calling a function with parameters
If you have experience in C/C++ or Java then you must be thinking about the return
type of the function and data type of arguments. That is possible in Python as well
(specifically for Python 3.5 and above).
Arguments of a Function:
Arguments are the values passed inside the parenthesis of the function. A function
can have any number of arguments separated by a comma.
Python supports various types of arguments that can be passed at the time of the
function call. Let’s discuss each type in detail.
Default arguments:
A default argument is a parameter that assumes a default value if a value is not
provided in the function call for that argument. The following example illustrates
Default arguments.
17
Keyword arguments:
The idea is to allow the caller to specify the argument name with values so that
caller does not need to remember the order of parameters.
Variable-length arguments
In Python, we can pass a variable number of arguments to a function using special
symbols. There are two special symbols:
*args (Non-Keyword Arguments)
**kwargs (Keyword Arguments)
Return statement in function:
The function return statement is used to exit from a function and go back to the
function caller and return the specified value or data item to the caller.
Syntax:
return [expression_list]
The return statement can consist of a variable, an expression, or a constant which is
returned to the end of the function execution. If none of the above is present with the
return statement a None object is returned.
Pass by Reference or pass by value:
One important thing to note is, in Python every variable name is a reference. When
we pass a variable to a function, a new reference to the object is created. Parameter
passing in Python is the same as reference passing in Java.
Anonymous functions in Python Function:
In Python, an anonymous function means that a function is without a name. As we
already know the def keyword is used to define the normal functions and the lambda
keyword is used to create anonymous functions. Please see this for details.
18
CONTROL STATEMENTS
Decision making is the most important aspect of almost all the programming
languages. As the name implies, decision making allows us to run a particular block
of code for a particular decision. Here, the decisions are made on the validity of the
particular conditions. Condition checking is the backbone of decision making
if statement:
The if statement is used to test a particular condition and if the condition is true, it
executes a block of code known as if-block. The condition of if statement can be any
valid logical expression which can be either evaluated to true or false.
The syntax of the if-statement is given below.
if expression:
statement
The if-else statement:
The if-else statement provides an else block combined with the if statement which
is executed in the false case of the condition.If the condition is true, then the if-block
is executed. Otherwise, the else-block is executed.
The syntax of the if-else statement is given below.
if condition:
#block of statements
else:
#another block of statements (else-block)
The elif statement:
The elif statement enables us to check multiple conditions and execute the specific
block of statements depending upon the true condition among them. We can have any
number of elif statements in our program depending upon our need. However, using
elif is optional. The elif statement works like an if-else-if ladder statement in C. It
must be succeeded by an if statement.
The syntax of the elif statement is given below.
if expression 1:
# block of statements
elif expression 2:
# block of statements
elif expression 3:
# block of statements
19
PYTHON LOOPS
The flow of the programs written in any programming language is sequential by
default. Sometimes we may need to alter the flow of the program. The execution of a
specific code may need to be repeated several numbers of times.
For this purpose, The programming languages provide various types of loops which
are capable of repeating some specific code several numbers of times.
while loop:
The while loop is also known as a pre-tested loop. In general, a while loop allows a
part of the code to be executed as long as the given condition is true.
It can be viewed as a repeating if statement. The while loop is mostly used in the case
where the number of iterations is not known in advance. The syntax is given below.
1. while expression:
2. statements
Using else with Python while loop:
Python enables us to use the while loop with the while loop also. The else block is
executed when the condition given in the while statement becomes false. Like for
loop, if the while loop is broken using break statement, then the else block will not be
executed and the statement present after else block will be executed.
Nested for loop in python:
Python allows us to nest any number of for loops inside a for loop. The inner loop
is executed n number of times for every iteration of the outer loop.
Python break statement :
The break is a keyword in python which is used to bring the program control out of
the loop. The break statement breaks the loops one by one, i.e., in the case of nested
loops, it breaks the inner loop first and then proceeds to outer loops. In other words,
we can say that break is used to abort the current execution of the program and the
control goes to the next line after the loop. The break is commonly used in the cases
where we need to break the loop for a given condition.
Python continue Statement:
The continue statement in python is used to bring the program control to the
beginning of the loop. The continue statement skips the remaining lines of code
inside the loop and start with the next iteration. It is mainly used for a particular
condition inside the loop so that we can skip some specific code for a particular
condition.
20
FILE HANDLING
Till now, we were taking the input from the console and writing it back to the
console to interact with the user.Sometimes, it is not enough to only display the data
on the console. The data to be displayed may be very large, and only a limited
amount of data can be displayed on the console, and since the memory is volatile, it is
impossible to recover the programmatically generated data again and again.
However, if we need to do so, we may store it onto the local file system which is
volatile and can be accessed every time. Here, comes the need of file handling. In this
section of the tutorial, we will learn all about file handling in python including,
creating a file, opening a file, closing a file, writing and appending the file, etc.
Opening a file:
Python provides the open() function which accepts two arguments, file name and
access mode in which the file is accessed. The function returns a file object which
can be used to perform various operations like reading, writing, etc.
The syntax to use the open() function is given below.
1. file object = open(<file-name>, <access-mode>, <buffering>)
The close() method:
Once all the operations are done on the file, we must close it through our python
script using the close() method. Any unwritten information gets destroyed once the
close() method is called on a file object.
We can perform any operation on the file externally in the file system is the file is
opened in python, hence it is good practice to close the file once all the operations are
done.
The syntax to use the close() method is given below.
1. fileobject.close()Reading the file
To read a file using the python script, the python provides us the read() method. The
read() method reads a string from the file. It can read the data in the text as well as
binary format.
The syntax of the read() method is given below.
21
1. fileobj.read(<count>)
Here, the count is the number of bytes to be read from the file starting from the
beginning of the file. If the count is not specified, then it may read the content of the
file until the end. Read Lines of the file.
Python facilitates us to read the file line by line by using a function readline(). The
readline() method reads the lines of the file from the beginning, i.e., if we use the
readline() method two times, then we can get the first two lines of the file .Consider
the following example which contains a function readline() that reads the first line of
our file "file.txt" containing three lines.
Writing the file:
To write some text to a file, we need to open the file using the open method with
one of the following access modes.
a: It will append the existing file. The file pointer is at the end of the file. It creates a
new file if no file exists.
w: It will overwrite the file if any file exists. The file pointer is at the beginning of the
file.
Reading the file :
To read a file using the python script, the python provides us the read() method. The
read() method reads a string from the file. It can read the data in the text as well as
binary format. The syntax of the read() method is given below. 1. fileobj.read() Here,
the count is the number of bytes to be read from the file starting from the beginning
of the file. If the count is not specified, then it may read the content of the file until
the end.
Read Lines of the file :
Python facilitates us to read the file line by line by using a function readline(). The
readline() method reads the lines of the file from the beginning, i.e., if we use the
readline() method two times, then we can get the first two lines of the file.
22
PYTHON OOPS CONCEPTS
Like other general purpose languages, python is also an object-oriented language
since its beginning. Python is an object-oriented programming language. It allows us
to develop applications using an Object Oriented approach. In Python, we can easily
create and use classes and objects.
Major principles of object-oriented programming system are given below.
 Object
 Class
 Method
 Inheritance
 Polymorphism
 Data Abstraction
 Encapsulation
Object:
The object is an entity that has state and behaviour. It may be any real-world object
like the mouse, keyboard, chair, table, pen, etc.
Everything in Python is an object, and almost everything has attributes and methods.
All functions have a built-in attribute __doc__, which returns the doc string defined
in the function source code.
Class:
The class can be defined as a collection of objects. It is a logical entity that has
some specific attributes and methods. For example: if you have an employee class
then it should contain an attribute and method, i.e. an email id, name, age, salary, etc.
Syntax
1. class ClassName:
2. <statement-1>
3. .
4. .
5. <statement-N>
Method:
The method is a function that is associated with an object. In Python, a method is
not unique to class instances. Any object type can have methods.
23
Inheritance:
Inheritance is the most important aspect of object-oriented programming which
simulates the real world concept of inheritance. It specifies that the child object
acquires all the properties and behaviours of the parent object. By using inheritance,
we can create a class which uses all the properties and behaviours of another class.
The new class is known as a derived class or child class, and the one whose
properties are acquired is known as a base class or parent class .It provides reusability of the code.
Polymorphism:
Polymorphism contains two words "poly" and "morphs". Poly means many and
Morphs means form, shape. By polymorphism, we understand that one task can be
performed in different ways. For example You have a class animal, and all animals
speak. But they and depends on the animal. So, the abstract "animal" concept does
not actually "speak", but specific animals (like dogs and cats) have a concrete
implementation of the action "speak".
Encapsulation:
Encapsulation is also an important aspect of object-oriented programming. It is
used to restrict access to methods and variables. In encapsulation, code and data are
wrapped together within a single unit from being modified by accident.
Data Abstraction:
Data abstraction and encapsulation both are often used as synonyms. Both are
nearly synonym because data abstraction is achieved through encapsulation.
Abstraction is used to hide internal details and show only functionalities. Abstracting
something means to give names to things so that the name captures the core of what a
function or a whole program does.
Python Class and Objects:
As we have already discussed, a class is a virtual entity and can be seen as a
blueprint of an object. The class came into existence when it instantiated. Let's
understand it by an example.
Suppose a class is a prototype of a building. A building contains all the details about
the floor, doors, windows, etc. we can make as many buildings as we want, based on
these details. Hence, the building can be seen as a class, and we can create as many
objects of this class.
On the other hand, the object is the instance of a class. The process of creating an
object can be called as instantiation.
24
In this section of the tutorial, we will discuss creating classes and objects in
python. We will also talk about how an attribute is accessed by using the class object.
Creating classes in python
In python, a class can be created by using the keyword class followed by the class
name.
The syntax to create a class is given below.
1. class ClassName:
2. #statement_suite
In python, we must notice that each class is associated with a documentation string
which can be accessed by using <class-name>.__doc__. A class contains a statement
suite including fields, constructor, function, etc. definition.
Consider the following example to create a class Employee which contains two fields
as Employee id, and name.
The class also contains a function display() which is used to display the information
of the Employee.
Example
1. class Employee:
2. id = 10;
3. name = "Aayush"
4. def display (self):
5. print(self.id,self.name)
Here, the self is used as a reference variable which refers to the current class
object. It is always the first argument in the function definition. However, using self
is optional in the function call.
25
Creating an instance of the class:
A class needs to be instantiated if we want to use the class attributes in another
class or method. A class can be instantiated by calling the class using the class name.
The syntax to create the instance of the class is given below.
1. <object-name> = <class-name>(<arguments>)
The following example creates the instance of the class Employee defined in the
above example.
Example
1. class Employee:
2. id = 10;
3. name = "TUSHAR"
4. def display (self):
5. print("ID: %d \nName: %s"%(self.id,self.name))
6. emp = Employee()
7. emp.display()
Output:
ID: 10
Name: TUSHAR
Advantages of Object-Oriented Programming:
•
Modularity for easier troubleshooting. When working with object- oriented
programming languages, you know exactly where to look when something goes
wrong. ...
•
Reuse of code through inheritance. ...
•
Flexibility through polymorphism. ...
•
Effective problem solving.
disadvantages of object-oriented :




Steep learning curve
Larger program size
Slower programs
Not suitable for all types of problems
26
MODULES & PACKAGES
Modules : A python module can be defined as a python program file which
contains a python code including python functions, class, or variables. In other
words, we can say that our python code file saved with the extension (.py) is treated
as the module. We may have a runnable code inside the python module .Modules in
Python provides us the flexibility to organize the code in a logical way.
To use the functionality of one module into another, we must have to import the
specific module.
Example
In this example, we will create a module named as file.py which contains a function f
that contains a code to print some message on the console.
Let's create the module named as file.py.
1. #displayMsg prints a message to the name being passed.
2. def displayMsg(name)
3. print("Hi "+name);
Here, we need to include this module into our main module to call the method
displayMsg() defined in the module named file.
Loading the module in our python code
We need to load the module in our python code to use its functionality. Python
provides
two types of statements as defined below.
1. The import statement
2. The from-import statement
The import statement:
The import statement is used to import all the functionality of one module into
another. Here, we must notice that we can use the functionality of any python source
file by importing that file as the module into another python source file.
We can import multiple modules with a single import statement, but a module is
loaded once regardless of the number of times, it has been imported into our file.
The syntax to use the import statement is given below.
1. import module1,module2,........ module n
Hence, if we need to call the function displayMsg() defined in the file file.py, we
have to import that file as a module into our module .
27
The from-import statement:
Instead of importing the whole module into the namespace, python provides the
flexibility to import only the specific attributes of a module. This can be done by
using from? import statement. The syntax to use the from-import statement is given
below.
1. from < module-name> import <name 1>, <name 2>..,<name n>
Consider the following module named as calculation which contains three functions
as summation, multiplication, and divide.
calculation.py:
1. #place the code in the calculation.py
2. def summation(a,b):
3. return a+b
4. def multiplication(a,b):
5. return a*b;
6. def divide(a,b):
7. return a/b;
Main.py:
1. from calculation import summation
2. #it will import only the summation() from calculation.py
3. a = int(input("Enter the first number"))
4. b = int(input("Enter the second number"))
5. print("Sum = ",summation(a,b)) #we do not need to specify the module name
while accessing summation()
from...import statement is always better to use if we know the attributes to be
imported from the module in advance. It doesn't let our code to be heavier. We can
also import all the attributes from a module by using *.
28
Renaming a module:
Python provides us the flexibility to import some module with a specific name
so that we can use this name to use that module in our python source file.
The syntax to rename a module is given below.
1. import <module-name> as <specific-name>
Using dir() function:
The dir() function returns a sorted list of names defined in the passed module. This
list contains all the sub-modules, variables and functions defined in this module.
The reload() function:As we have already stated that, a module is loaded once
regardless of the number of times it is imported into the python source file. However,
if you want to reload the already imported module to re-execute the top-level code,
python provides us the reload() function. The syntax to use the reload() function is
given below.
1. reload(<module-name>)
for example, to reload the module calculation defined in the previous example, we
must
use the following line of code.
1. reload(calculation)
Python packages:
The packages in python facilitate the developer with the application
development environment by providing a hierarchical directory structure where a
package contains sub-packages, modules, and sub-modules. The packages are used to
categorize the application level code efficiently.
Let's create a package named Employees in your home directory. Consider the
following steps.
1. Create a directory with name Employees on path /home.
2. Create a python source file with name ITEmployees.py on the path
/home/Employees.
ITEmployees.py
1. def getITNames():
2. List = ["John", "David", "Nick", "Martin"]
3. return List;
3. Similarly, create one more python file with name BPOEmployees.py and create a
function getBPONames().
4. Now, the directory Employees which we have created in the first step contains two
python modules. To make this directory a package, we need to include one more file
29
here, that is __init__.py which contains the import statements of the modules defined
in this directory.
__init__.py
1. from ITEmployees import getITNames
2. from BPOEmployees import getBPONames
5. Now, the directory Employees has become the package containing two python
modules. Here we must notice that we must have to create __init__.py inside a
directory
to convert this directory to a package.
6. To use the modules defined inside the package Employees, we must have to import
this in our python source file. Let's create a simple python source file at our home
directory (/home) which uses the modules defined in this package.
Test.py
1. import Employees
2. print(Employees.getNames())
Output:
['John', 'David', 'Nick', 'Martin']
We can have sub-packages inside the packages. We can nest the packages up to any
level depending upon the application requirements.
30
PYTHON EXCEPTIONS
An exception can be defined as an abnormal condition in a program resulting in
the disruption in the flow of the program.
Whenever an exception occurs, the program halts the execution, and thus the
further code is not executed. Therefore, an exception is the error which python script
is unable to tackle with Python provides us with the way to handle the Exception so
that the other part of the code can be executed without any disruption. However, if we
do not handle the exception, the interpreter doesn't execute all the code that exists
after the that.
Common Exceptions
A list of common exceptions that can be thrown from a normal python program is
given below.
1. ZeroDivisionError: Occurs when a number is divided by zero.
2. NameError: It occurs when a name is not found. It may be local or global.
3. IndentationError: If incorrect indentation is given.
4. IOError: It occurs when Input Output operation fails.
5. EOFError: It occurs when the end of the file is reached, and yet operations are
being performed.
Problem without handling exceptions
As we have already discussed, the exception is an abnormal condition that halts the
execution of the program.
31
EXCEPTION HANDLING IN PYTHON
If the python program contains suspicious code that may throw the exception, we
must place that code in the try block. The try block must be followed with the except
statement which contains a block of code that will be executed if there is some
exception in the try block.
Syntax
1. try:
2. #block of code
3.
4. except Exception1:
5. #block of code
6.
7. except Exception2:
8. #block of code
9.
10. #other code
The except statement with no exception:
Python provides the flexibility not to specify the name of exception with the except
statement.
Declaring multiple exceptions:
The python allows us to declare the multiple exceptions with the except clause.
Declaring multiple exceptions is useful in the cases where a try block throws multiple
exceptions.
Syntax
1. try:
2. #block of code
3.
4. except (<Exception 1>,<Exception 2>,<Exception 3>,...<Exception n>)
5. #block of code
6.
7. else:
8. #block of code
32
The finally block:
We can use the finally block with the try block in which, we can pace the important
code which must be executed before the try statement throws an exception.
syntax
1. try:
2. # block of code
3. # this may throw an exception
4. finally:
5. # block of code
6. # this will always be executed
Raising exceptions:
An exception can be raised by using the raise clause in python. The syntax to use the
raise statement is given below.
syntax
1. raise Exception_class,<value>
To raise an exception, raise statement is used. The exception class name follows it.
An exception can be provided with a value that can be given in the parenthesis.
To access the value "as" keyword is used. "e" is used as a reference variable which
stores the value of the exception
Custom Exception:
The python allows us to create our exceptions that can be raised from the program
and caught using the except clause. However, we suggest you read this section after
visiting the Python object and classes.
33
PROJECT TITLE: STUDENT MANAGEMENT SYSTEM
Project overview :
Project Name:
Student Management
System Project in Python
Abstract:
This is a GUI-based program in
python that includes basically
make use of the Tkinter and Sqlite
database for the execution.
Language/Technologies Used:
Python, Tkinter
IDE
idle(Recommended)
Database
SQLite3
Python version (Recommended):
3.8 or 3.9
Type/Category:
Final year project using
python
34
Python Code of the project:
#import libraries
from tkinter import *
import tkinter.ttk as ttk
import tkinter.messagebox as tkMessageBox
import sqlite3
#function to define database
def Database():
global conn, cursor
#creating student database
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
#creating STUD_REGISTRATION table
cursor.execute(
"CREATE TABLE IF NOT EXISTS STUD_REGISTRATION (STU_ID INTEGER
PRIMARY KEY, STU_NAME TEXT, STU_CONTACT TEXT, STU_EMAIL TEXT,
STU_ROLLNO TEXT, STU_BRANCH TEXT)")
#defining function for creating GUI Layout
def DisplayForm():
#creating window
display_screen = Tk()
#setting width and height for window
display_screen.geometry("900x400")
#setting title for window
display_screen.title("my project")
global tree
global SEARCH
global name,contact,email,rollno,branch
SEARCH = StringVar()
name = StringVar()
contact = StringVar()
email = StringVar()
rollno = StringVar()
branch = StringVar()
#creating frames for layout
#topview frame for heading
TopViewForm = Frame(display_screen, width=600, bd=1, relief=SOLID)
TopViewForm.pack(side=TOP, fill=X)
#first left frame for registration from
LFrom = Frame(display_screen, width="350")
LFrom.pack(side=LEFT, fill=Y)
#seconf left frame for search form
35
LeftViewForm = Frame(display_screen, width=500,bg="gray")
LeftViewForm.pack(side=LEFT, fill=Y)
#mid frame for displaying students record
MidViewForm = Frame(display_screen, width=600)
MidViewForm.pack(side=RIGHT)
#label for heading
lbl_text = Label(TopViewForm, text="Student Management System", font=('verdana',
18), width=600,bg="#1C2833",fg="white")
lbl_text.pack(fill=X)
#creating registration form in first left frame
Label(LFrom, text="Name ", font=("Arial", 12)).pack(side=TOP)
Entry(LFrom,font=("Arial",10,"bold"),textvariable=name).pack(side=TOP, padx=10,
fill=X)
Label(LFrom, text="Contact ", font=("Arial", 12)).pack(side=TOP)
Entry(LFrom, font=("Arial", 10, "bold"),textvariable=contact).pack(side=TOP, padx=10,
fill=X)
Label(LFrom, text="Email ", font=("Arial", 12)).pack(side=TOP)
Entry(LFrom, font=("Arial", 10, "bold"),textvariable=email).pack(side=TOP, padx=10,
fill=X)
Label(LFrom, text="Rollno ", font=("Arial", 12)).pack(side=TOP)
Entry(LFrom, font=("Arial", 10, "bold"),textvariable=rollno).pack(side=TOP, padx=10,
fill=X)
Label(LFrom, text="Branch ", font=("Arial", 12)).pack(side=TOP)
Entry(LFrom, font=("Arial", 10, "bold"),textvariable=branch).pack(side=TOP, padx=10,
fill=X)
Button(LFrom,text="Submit",font=("Arial", 10,
"bold"),command=register).pack(side=TOP, padx=10,pady=5, fill=X)
#creating search label and entry in second frame
lbl_txtsearch = Label(LeftViewForm, text="Enter name to Search", font=('verdana',
10),bg="gray")
lbl_txtsearch.pack()
#creating search entry
search = Entry(LeftViewForm, textvariable=SEARCH, font=('verdana', 15), width=10)
search.pack(side=TOP, padx=10, fill=X)
#creating search button
btn_search = Button(LeftViewForm, text="Search", command=SearchRecord)
btn_search.pack(side=TOP, padx=10, pady=10, fill=X)
#creating view button
btn_view = Button(LeftViewForm, text="View All", command=DisplayData)
btn_view.pack(side=TOP, padx=10, pady=10, fill=X)
#creating reset button
btn_reset = Button(LeftViewForm, text="Reset", command=Reset)
btn_reset.pack(side=TOP, padx=10, pady=10, fill=X)
#creating delete button
36
btn_delete = Button(LeftViewForm, text="Delete", command=Delete)
btn_delete.pack(side=TOP, padx=10, pady=10, fill=X)
#setting scrollbar
scrollbarx = Scrollbar(MidViewForm, orient=HORIZONTAL)
scrollbary = Scrollbar(MidViewForm, orient=VERTICAL)
tree = ttk.Treeview(MidViewForm,columns=("Student Id", "Name", "Contact",
"Email","Rollno","Branch"),
selectmode="extended", height=100, yscrollcommand=scrollbary.set,
xscrollcommand=scrollbarx.set)
scrollbary.config(command=tree.yview)
scrollbary.pack(side=RIGHT, fill=Y)
scrollbarx.config(command=tree.xview)
scrollbarx.pack(side=BOTTOM, fill=X)
#setting headings for the columns
tree.heading('Student Id', text="Student Id", anchor=W)
tree.heading('Name', text="Name", anchor=W)
tree.heading('Contact', text="Contact", anchor=W)
tree.heading('Email', text="Email", anchor=W)
tree.heading('Rollno', text="Rollno", anchor=W)
tree.heading('Branch', text="Branch", anchor=W)
#setting width of the columns
tree.column('#0', stretch=NO, minwidth=0, width=0)
tree.column('#1', stretch=NO, minwidth=0, width=100)
tree.column('#2', stretch=NO, minwidth=0, width=150)
tree.column('#3', stretch=NO, minwidth=0, width=80)
tree.column('#4', stretch=NO, minwidth=0, width=120)
tree.pack()
DisplayData()
#function to insert data into database
def register():
Database()
#getting form data
name1=name.get()
con1=contact.get()
email1=email.get()
rol1=rollno.get()
branch1=branch.get()
#applying empty validation
if name1=='' or con1==''or email1=='' or rol1==''or branch1=='':
tkMessageBox.showinfo("Warning","fill the empty field!!!")
else:
#execute query
conn.execute("""INSERT INTO STUD_REGISTRATION
(STU_NAME,STU_CONTACT,STU_EMAIL,STU_ROLLNO,STU_BRANCH) \
VALUES (?,?,?,?,?)""",(name1,con1,email1,rol1,branch1));
conn.commit()
37
tkMessageBox.showinfo("Message","Stored successfully")
#refresh table data
DisplayData()
conn.close()
def Reset():
#clear current data from table
tree.delete(*tree.get_children())
#refresh table data
DisplayData()
#clear search text
SEARCH.set("")
name.set("")
contact.set("")
email.set("")
rollno.set("")
branch.set("")
def Delete():
#open database
Database()
if not tree.selection():
tkMessageBox.showwarning("Warning","Select data to delete")
else:
result = tkMessageBox.askquestion('Confirm', 'Are you sure you want to delete this
record?', icon="warning")
if result == 'yes':
curItem = tree.focus()
contents = (tree.item(curItem))
selecteditem = contents['values']
tree.delete(curItem)
cursor=conn.execute("DELETE FROM STUD_REGISTRATION WHERE STU_ID
= %d" % selecteditem[0])
conn.commit()
cursor.close()
conn.close()
#function to search data
def SearchRecord():
#open database
Database()
#checking search text is empty or not
if SEARCH.get() != "":
#clearing current display data
tree.delete(*tree.get_children())
#select query with where clause
38
cursor=conn.execute("SELECT * FROM STUD_REGISTRATION WHERE
STU_NAME LIKE ?", ('%' + str(SEARCH.get()) + '%',))
#fetch all matching records
fetch = cursor.fetchall()
#loop for displaying all records into GUI
for data in fetch:
tree.insert('', 'end', values=(data))
cursor.close()
conn.close()
#defining function to access data from SQLite database
def DisplayData():
#open database
Database()
#clear current data
tree.delete(*tree.get_children())
#select query
cursor=conn.execute("SELECT * FROM STUD_REGISTRATION")
#fetch all data from database
fetch = cursor.fetchall()
#loop for displaying all data in GUI
for data in fetch:
tree.insert('', 'end', values=(data))
cursor.close()
conn.close()
#calling function
DisplayForm()
if name=='__main_':
#Running Application
mainloop()
39
input:
entering the data in database
Output:
data stored in the database
40
PYTHON USE CASES








Creating web applications on a server
Building workflows that can be used in conjunction with software
Connecting to database systems
Reading and modifying files
Performing complex mathematics
Processing big data
Fast prototyping
Developing production-ready software
Advantages of python:
1.Easy to read and understand
2.Free and open source
3.It increases productivity
4.Interpreted language
5.Dynamically typed
6.Extensive library
7.It supports with object oriented environment
Disadvantages of python:
1.Speed limitations such as execution speed is low
2.Weak in mobile computing and browsers
3.Database accesses are slow and takes time
4.Design restrictions and it has Run time errors
5. Not memory efficient
6.Underdeveloped database connections and layers
7. It is slow primarily due to its dynamic Nature And dynamic versalities.
41
Conclusion






Python is a fully-fledged programming language. Any code you
download from github, the Python Package Index, or anywhere else,
can be malicious and would almost certainly go unnoticed by most
people's firewalls.
Python serves well as the first to learn, even better as the glue when
working with other language or tools.
Python is an easy-to-use ,robust programming language that is freely
available.
Python's object and functions are very versatile.
Python is a very high -level object oriented language.
In this way we are going to develop the student management system,
which is very usefull.so we created a user interface friendly environment.it
facilitates and manages key administrative processes and maintain the
information on the database
42
DONE By
ARBIND TUSHAR PATHAK
20280-CM-002
43
Download