0% found this document useful (0 votes)
33 views75 pages

Venkata Vinod

The document is an internship report submitted by Akula Venkata Vinod to fulfill the requirements for a Bachelor of Technology degree in Electronic and Communications Engineering. It describes the internship, which took place from August 14, 2023 to September 20, 2023 under the supervision of Sarvesh Madhu Agrawal at Internshala trainings. The report provides an overview of the weekly activities during the internship, which focused on learning Python fundamentals, machine learning concepts, and programming with Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views75 pages

Venkata Vinod

The document is an internship report submitted by Akula Venkata Vinod to fulfill the requirements for a Bachelor of Technology degree in Electronic and Communications Engineering. It describes the internship, which took place from August 14, 2023 to September 20, 2023 under the supervision of Sarvesh Madhu Agrawal at Internshala trainings. The report provides an overview of the weekly activities during the internship, which focused on learning Python fundamentals, machine learning concepts, and programming with Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

INTERNSHIP REPORT

A report submitted in partial fulfilment of the requirements for the Award


Degree of

BACHELOR OF TECHNOLOGY
in

ELECTRONIC AND COMMUNICATIONS ENGINEERING


By
AKULA VENKATA VINOD

Regd.No.:21781A0403

Under Supervision of
SARVESH MADHU AGRAWAL, Team lead
INTERNSHALA trainings
(14/08/2023 to 20/09/2023)

SRI VENKATESWARA COLLEGE OF ENGINEERING& TECHNOLOGY


(AUTONOMOUS)
R.V.S NAGAR, CHITTOOR – 517 127. (A.P)
(Approved by AICTE, New Delhi, Affiliated to JNTUA, Anantapuramu)
(Accredited by NBA, New Delhi & NAAC, Bengaluru) (An ISO 9001:2000
Certified Institution) 2023-2024
CERTIFICATE OF INTERNSHIP
CERTIFICATE

SRI VENKATESWARA COLLEGE OF ENGINEERING& TECHNOLOGY


(AUTONOMOUS)
R.V.S NAGAR, CHITTOOR – 517 127. (A.P)
(Approved by AICTE, New Delhi, Affiliated to JNTUA, Anantapuramu)
(Accredited by NBA, New Delhi & NAAC, Bengaluru) (An ISO 9001:2000
Certified Institution)

CERTIFICATE
This is to certify that the “Internship report” submitted by AKULA
VENKATA VINOD
(Regd.No.:21781A0403) is work done by him/her and submitted during
2023- 2024
BACHELOR OF TECHNOLOGY in ELECTRONICS AND
COMMUNICATION ENGINEERING academic year, in partial ful fillment of
the requirements for the award of the degree of ELECTRONICS AND
COMMUNICATION ENGINEERING,INTERNSHALA

InternshipCoordinator Head of the Department


CERTIFICATE OF INTERNSHIP
CERTIFICATE
ACKNOWLEDGEMENT

A grateful thanks to Dr.R.Venkataswamy, Chairman of Sri


Venkateswara College
of Engineering & Technology for providing education in their
esteemed institution.
I wish to record my deep sense of gratitude and profound thanks to our
beloved

Vice Chairman, Sri R.V.Srinivas for his valuable support throughout the
course.

I express our sincere thanks to Dr.M.MOHAN BABU, our beloved


principal for his
encouragement and suggestion during the course of study.
With the deep sense of gratefulness, I acknowledge Dr.
T.SOMASSOUNDARAM, Head of the Department, Electronics and
Communication Engineering, for giving us inspiring guidance in undertaking
internship.
I express our sincere thanks to the internship coordinator, for her keen
interest, stimulating guidance, constant encouragement with our work during
all stages, to bring this report into fruition.
I wish to convey my gratitude and sincere thanks to all members for their
support and
cooperation rendered for successful submission of report.
Finally, I would like to express my sincere thanks to all teaching,
nonteaching faculty members, our parents, friends and for all those who
havesupported us to complete the internship successfully.

WEEKLY OVER VIEW OF INTERNSHIP ACTIVITIES


DAY NAMEOFTHETOPIC/MODULECOMPLETE
DATE D
14/08/202 Monday INTRODUCTION TO PYTHON
3
16/08/2023 Wednesda Python fundamental
y

19/08/2023 Saturday History of python


DATE DAY NAMEOFTHETOPIC/MODULECOMPLETED
21/08/2023 Monday Data type,lists
22 /08/2023 Tuesday Dictonary,string
23/08/2023 Wednesday Conditions,loops
24/08/2023 Thursday Inbuilt and user-defined
functions
25/08/2023 Friday Numpy
26/08/2023 Saturday Error Handling

DATE DAY NAMEOFTHETOPIC/MODULECOMPLET


ED
28/08/202 Monday Io functions
3
29/08/202 Tuesday Pandas Introduction
3
30/08/2023 Wednesda Pandas and visualization
y introduction
31/08/2023 Thursday Pandas and visualization

01/09/2023 Friday Introduction to probabilty


02/09/2023 Saturday Distribution theorem
DATE DAY NAMEOFTHETOPIC/MODULECOMPLETED
04/09/2023 Monday Hypothesis testing
05/09/2023 Tuesday Machine learning introduction
06/09/2023 Wednesday Supervised and unsupervised learning

DATE DAY NAMEOFTHETOPIC/MODULECOMPLETED

11/09/2023 Monday Classification VS regreession


12/09/2023 Tuesday Training ,testing
13/09/2023 Wednesday Cross validation
14/09/2023 Thursday Data features
15/09/2023 Friday Label picking
16/09/2023 Saturday Error matric

DATE DAY NAMEOFTHETOPIC/MODULECOMPLETED

18/09/2023 Monday Conclusion

19/09/2023 Tuesday Discussion about major project

20/09/2023 Wednesday
MACHINE LERANING WITH PYTHON

ABSTRACT

The field of machine learning is introduced at a conceptual level. Ideas such


as supervised and unsupervised as well as regression and
classification are explained. The tradeoff between bias, variance, and
model complexity is discussed as a central guiding idea of learning.
Various types of model that machine learning can produce are
introduced such as the neural network (feed-forward and recurrent),
support vector machine, random forest, selforganizing map, and
Bayesian network. Training a model is discussed next with its main
ideas of splitting a dataset into training, testing, and validation sets as
well as performing crossvalidation. Assessing the goodness of the
model is treated next alongside the essential role of the domain
expert in keeping the project real. The chapter concludes with some
practical advice on how to perform a machine learning project.
MACHINE LERANING WITH PYTHON

Contents
Chapter-1
.............................................................................................................................
..................
1
INTRODUCTION
................................................................................................................ .................
1
Scripting Language
................................................................................................................................
1
Object Oriented Programming Language
........................................................................................ ...... 1
History .....................................................................................................................
..............................
2
Chapter-2 ...........................................................................................................................
....................
3 Downloading & Installing Python
......................................................................................................... 3
2.1 Downloading python
...................................................................................................... .................
3
2.2 Installing Python .......................................................................................................
.......................
4
2.3 Setup the Path Variable
................................................................................................. ..................
5
2.4 Running The Python IDE
..................................................................................................
.............. 7
PROGRAMMING WITH PYTHON

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS),


CHITTOOR
Chapter-3 ...........................................................................................................................
....................
9 DATA TYPES &
OPERATORS. ........................................................................................................ 9
3.1 Data types ..............................................................................................................
..........................
9
3.2 Variables ...............................................................................................................
...........................
9
3.3 String...................................................................................................................
.............................
9
3.4 Python operators ........................................................................................................
......................
9 Chapter-4
...........................................................................................................................
..................
11
4.1 Tuples ..................................................................................................................
..........................
11
PROGRAMMING WITH PYTHON

PROGRAMMING WITH PYTHON

Chapter-5
...........................................................................................................................
..................
14 Loops& conditional statements

........................................................................................................... 14
5.1 Loop definition
..............................................................................................................................
1
5.2 Conditional Statements:
................................................................................................. ................
15 5.3 Function
.............................................................................................................................
............

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS),


CHITTOOR
Chapter-1

INTRODUCTION
Python is a widely used high-level, general-purpose,
interpreted, dynamic programming language. Its design
philosophy emphasizes code readability, and its syntax
allows programmers to express concepts in fewer lines
of code than would be possible in languages such as C++
or Java. The language provides constructs intended to
enable clear programs on both a small and large scale.

Python supports multiple programming paradigms,


including object-oriented, imperative and functional
programming or procedural styles. It features a dynamic
type system and automatic memory management and has a
large and comprehensive standard library. Python interpreters
are available for installation on many operating systems,
allowing Python code execution on a wide variety of
systems.

Scripting Language
A scripting or script language is a programming language
that supports scripts, programs written for a special runtime
environment that automate the execution of tasks that could
alternatively be executed one-by-one by a human operator.
PROGRAMMING WITH PYTHON

Scripting languages are often interpreted (rather


than compiled). Primitives are usually the
elementary tasks or API calls, and the language
allows them to be combined into more complex
programs. Environments that can be automated
through scripting include software
applications, web pages within a web browser, the
shells of operating systems

A scripting language can be viewed as a


domainspecific language for a particular
environment; in the case of scripting an
application, this is also known as an
extension language. Scripting languages
are also sometimes referred to as very
high-level programming languages, as they
operate at a high level of abstraction, or as
control languages.
Object Oriented Programming Language

SRI VENKATESWARA COLLEGE OF ENGINEERING &


TECHNOLOGY (AUTONOMOUS), CHITTOOR
PAGE-1

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS),


CHITTOOR
PROGRAMMING WITH PYTHON

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS),


CHITTOOR
Object-oriented programming (OOP) is a programming
paradigm based on the concept of "objects", which may
PROGRAMMING WITH PYTHON

contain data, in the form of fields, often known as attributes;


and code, in the form of procedures, often known as methods.
A distinguishing feature of objects is that an object's
procedures can access and often modify the data fields of the
object with which they are associated (objects have a notion of
"this" or "self").

In OO programming, computer programs are designed by making


them out of objects that interact with one another. There is
significant diversity in
objectoriented programming, but most popular languages are
class-based, meaning that objects are instances of classes, which
typically also determines their type.

History

Python was conceived in the late 1980s, and its implementation


was started in December
1989 by Guido van Rossum at CWI in the Netherlands as a
successor to the ABC language (itself inspired by SETL)
capable of exception handling and interfacing with the Amoeba
operating system. Van Rossum is Python's principal author, and
his continuing central role in deciding the direction of Python is
reflected in the title given to him by the Python community,
benevolent dictator for life (BDFL).

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS),


CHITTOOR
PROGRAMMING WITH PYTHON

Chapter-2
Downloading & Installing
Python
About the Behind The Scene of Python origin of Python, Van Rossum wrote in
1996:

Over six years ago, in December 1989, I was looking for a "hobby"
programming project that would keep me occupied during the week
around Christmas. My office ... would be closed, but I had a home
Computer, and not much else on my hands. I decided to write an interpreter
for the new scripting language I had been thinking about lately: a descendant
of ABC that would appeal to Unix/C hackers. I chose Python as a working
title for the project, being in a slightly irreverent mood (and a big fan of Monty
Python's Flying Circus).
2.1 Downloading python
If you don’t already have a copy of Python installed on your
computer, you will need to open up your Internet browser and
go to the Python download page
(http://www.python.org/download/).

Now that you are on the download page, select which of the
software builds you would like to download. For the
purposes of this article we will use the most up to date
version available (Python 3.4.1).

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-8
PROGRAMMING WITH PYTHON

Once you have clicked on that, you will be taken to a


page with a description of all the new updates and
features of 3.4.1, however, you can always read that
while the download is in process. Scroll to the bottom of
the page till you find the “Download” section and click
on the link that says “download page.”

Now you will scroll all the way to the bottom of the page and find
the
“Windows x86 MSI installer.” If you want to download
the 86-64 bit MSI, feel free to do so. We believe that even
if you have a 64-bit operating system installed on your
computer, the 86-bit MSI is preferable. We say this
because it will still run well and sometimes, with the
64bit architectures, some of the compiled binaries and
Python libraries don’t work well.

2.2 Installing

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-9
PROGRAMMING WITH PYTHON

Python

Once you have downloaded the Python MSI, simply navigate to


the download location on your computer, double clicking the file
and pressing Run when the dialog box pops up.

If you are the only person who uses your computer, simply leave
the
“Install for all users” option selected. If you have multiple
accounts on your PC and don’t want
to install it across all accounts, select the “Install just for me”
option then press “Next.”

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-10
PROGRAMMING WITH PYTHON

if you want to change the install location, feel free to do so;


however, it is best to leave it as is and simply select next,
Otherwise.. Scroll down in the window and find the “Add
Python.exe to Path” and click on the small red

“x.” Choose the “Will be installed on local hard drive” option then
press

“Next.”

2.3 Setup the Path Variable


Begin by opening the start menu and typing in “environment” and
select the option Called

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-11
PROGRAMMING WITH PYTHON

“Edit the system environment variables.”

When the “System Properties” window appears, click on


“Environment Variables…” Once you have the “Environment
Variables” window open, direct your focus to the bottom half. You
will notice that it controls all the “System Variables” rather than
just this associated with your user. Click on “New…” to create a
new variable for Python.

Simply enter a name for your Path and the code shown
below. For the purposes of this example we have installed
Python 2.7.3, so we will call the path: “Python path.” The
string that you will need to enter is:
“C:\Python27\;C:\Python27\Scripts;”

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-12
PROGRAMMING WITH PYTHON

2.4 Running The Python IDE

Now that we have successfully completed the installation process


and added our
“Environment Variable,” you are ready to create your first basic
Python script. Let’s begin by opening Python’s GUI by pressing
“Start” and typing “Python” and selecting the “IDLE (Python
GUI).”

Once the GUI is open, we will begin by using the simplest


directive possible. This is the “print” directive which simply
prints whatever you tell it to, into a new line. Start by typing

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-13
PROGRAMMING WITH PYTHON

a print directive like the one shown in the image below or


copy and paste this text then press

“Enter”: print (“Congratulations on executing your first print


directive!”)

Python Code Execution


Python’s traditional runtime execution model: source code
you type is translated to byte code, which is then run by the
Python Virtual Machine. Your code is automatically
compiled, but then it is interpreted.

Source code extension is .py

Byte code extension is .pyc (compiled python code)

chapter-3
DATA TYPES & OPERATORS 3.1 Data types

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-14
PROGRAMMING WITH PYTHON

(this is called dynamic typing). Data types determine whether


an object can do something, or whether it just would not make
sense. Other programming languages often determine whether
an operation makes sense for an object by making sure the
object can never be stored somewhere where the operation
will be performed on the object (this type system is called
static typing). Python does not do that. Instead it stores the
type of an object with the object, and checks when the
operation is performed whether that operation makes sense for
that object Python has many native data types. Here are the
important ones:

Booleans: are either True or False.


Numbers: can be integers (1 and 2), floats (1.1 and 1.2), fractions
(1/2 and 2/3), or even complex numbers.
Strings: are sequences of Unicode characters, e.g. an HTML
document.
Bytes and byte arrays:e.g. a JPEG image file.
Lists: are ordered sequences of values.
Tuples: are ordered, immutable sequences of values.
Sets: are unordered bags of values.

3.2 Variables
Variables are nothing but reserved memory locations to store
values. This means that when you create a variable you
reserve some space in memory. Based on the data type of a
variable, the interpreter allocates memory and decides what
can be stored in the reserved memory. Therefore, by
assigning different data types to variables, you can store
integers, decimals or characters in these variables.
Ex: counter = 100 #
An integer assignment miles = 1000.0
# A floating point name = "John"
# A string

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-15
PROGRAMMING WITH PYTHON

3.3 String
In programming terms, we usually call text a string. When you think of
a string as a collection of letters, the term makes sense.

All the letters, numbers, and symbols in this


book could be a string. For that matter, your
name could be a string, and so could your
address.

3.4 Python operators

Arithmetic Operators

Comparison Operator

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-16
PROGRAMMING WITH PYTHON

Chapter-4
Tuples &list

4.1 Tuples
A tuple is a sequence of immutable Python objects. Tuples are
sequences, just like lists. The differences between tuples and lists
are, the tuples cannot be changed unlike lists and tuples use
parentheses.
Accessing Values in Tuples:
To access values in tuple, use the square brackets for slicing along
with the index or indices to obtain value available at that index.
For example − tup1 = ('physics',
'chemistry', 1997,
2000); tup2 = (1, 2, 3, 4, 5, 6, 7 ); print "tup1[0]: ", tup1[0] print
"tup2[1:5]: ", tup2[1:5] When the above code is executed, it
produces the following result − tup1[0]: physics tup2[1:5]: [2, 3,
4, 5]

Basic Tuples Operations

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-17
PROGRAMMING WITH PYTHON

Tuples respond to the + and * operators much like strings;


they mean concatenation and repetition here too, except that
the result is a new tuple, not a string. In fact, tuples respond to
all of the general sequence operations we used on strings in
the prior chapter –

Built-in Tuple Functions


Python includes the following tuple functions –

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-18
PROGRAMMING WITH PYTHON

LISTS

4.2 List
The list is a most versatile datatype available in Python which can
be written as a list of commaseparated values (items) between
square brackets.
Important thing about a list is that items in a list need not be of the
same type.

Creating a list is as simple as putting different


commaseparated values between square brackets. For
example − list1 = ['physics', 'chemistry', 1997,
2000]; list2 = [1, 2, 3, 4, 5 ]; list3 = ["a", "b", "c", "d"]; Similar
to string indices, list indices start at 0, and lists can be sliced,
concatenated and so on.
Accessing Values in Lists:
To access values in lists, use the square brackets for slicing along
with the index or indices to obtain value available at that index.
For example − list1 =
['physics', 'chemistry', 1997, 2000]; list2 = [1, 2,
3, 4, 5, 6, 7 ]; print "list1[0]: ", list1[0] print "list2[1:5]:
", list2[1:5] Output: list1[0]: physics list2[1:5]:

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-19
PROGRAMMING WITH PYTHON

[2, 3, 4, 5]
Update: list = ['physics', 'chemistry', 1997, 2000]; print
"Value available at index 2 : " print list[2] list[2] = 2001; print
"New value available at index 2 : " print list[2]
Output: Value available at index 2 : 1997
New value available at index 2 : 2001

Delete: list1 = ['physics', 'chemistry',


1997, 2000]; print list1 del list1[2];
print "After deleting value at index 2 : "
print list1 ['physics', 'chemistry', 1997,
2000] Output:
After deleting value at index 2 : ['physics',
'chemistry', 2000]
4.3 Basic List Operation

Built-in List Functions & Methods Python includes following list


methods

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-20
PROGRAMMING WITH PYTHON

Chapter-5
Loops& conditional statements
5.1 Loop definition

Programming languages provide various control structures that


allow for more complicated execution paths.

A loop statement allows us to execute a statement or group of


statements multiple times.
The following diagram illustrates a loop statement –

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-21
PROGRAMMING WITH PYTHON

Python programming language provides following types of loops


to handle looping requirements.

Loop Example:
For Loop:
>>> for mynum in [1, 2, 3, 4, 5]:
print ("Hello", mynum )
Hello 1
Hello 2
Hello 3

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-22
PROGRAMMING WITH PYTHON

Hello 4

:
>>> count = 0
>>while(count< 4): print
'The count is:', count
count = count + 1 The
count is:
0
The count is: 1
The count is: 2
The count is: 3

5.2 Conditional Statements:


Decision making is anticipation of conditions occurring while
execution of the program and specifying actions taken according
to the conditions.

Decision structures evaluate multiple expressions which


produce TRUE or FALSE as outcome. You need to
determine which action to take and which statements to
execute if outcome is TRUE or FALSE otherwise.

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-23
PROGRAMMING WITH PYTHON

Python programming language provides following types of


decision making statements.
Click the following links to check their detail.

Example:
If
Stat
em
ent:
a=3 3
b=2

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-24
PROGRAMMING WITH PYTHON

00 If
b>a:
print(
“b”)
If...E
lse

Statement
: a=200
b=33 if
b>a:
print(“b is greater than a”) else:
print(“a is greater than b”)

5.3 Function

Function blocks begin with the keyword def followed by the


function name and parentheses(
( ) ).
Any input parameters or arguments should be placed within these
parentheses.
You can also define parameters inside these
parentheses. The first statement of a function can be
an optional statement - the documentation string of the
function.

The code block within every function starts with a colon (:) and is
indented.

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-25
PROGRAMMING WITH PYTHON

The statement return [expression] exits a function, optionally


passing back an expression to the caller. A return statement with no
arguments is the same as return None.

Synte
x: Def functionname(param):
“function_docstring”
Function_suite
Return[expression] Def
printme(str):
“this print a passed string into this function”
print str return
1. # Function definition is here
def printme( str ):
"This prints a passed string into this
function" print str return;
# Now you can call printme function
printme("I'm first call to user defined
function!")

printme("Again second call to the same function”

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-26
PROGRAMMING WITH PYTHON

In Python, object-oriented Programming (OOPs) is a programming paradigm that


uses objects and classes in programming. It aims to implement real-world entities
like inheritance, polymorphisms, encapsulation, etc. in the programming. The main
concept of OOPs is to bind the data and the functions that work on that together as
a single unit so that no other part of the code can access this data. OOPs Concepts
in Python
• Class
• Objects
• Polymorphism
• Encapsulation
• Inheritance
• Data Abstraction

Python OOPs Concepts

Python Class
A class is a collection of objects. A class contains the blueprints or the prototype
from which the objects are being created. It is a logical entity that contains some
attributes and methods.

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-27
PROGRAMMING WITH PYTHON

To understand the need for creating a class let’s consider an example, let’s say you
wanted to track the number of dogs that may have different attributes like breed,
and age. If a list is used, the first element could be the dog’s breed while the second
element could represent its age. Let’s suppose there are 100 different dogs, then
how would you know which element is supposed to be which? What if you wanted
to add other properties to these dogs? This lacks organization and it’s the exact need
for classes.
Some points on Python class:
• Classes are created by keyword class.
• Attributes are the variables that belong to a class.
• Attributes are always public and can be accessed using the dot
(.) operator. Eg.: Myclass.Myattribute Class Definition Syntax: class
ClassName: # Statement-1
.
.
.
# Statement-N

Creating an Empty Class in Python


In the above example, we have created a class named Dog using the class keyword.

Python Objects
The object is an entity that has a state and behavior associated with it. It may be any
real-world object like a mouse, keyboard, chair, table, pen, etc. Integers, strings,
floating-point numbers, even arrays, and dictionaries, are all objects. More
specifically, any single integer or any single string is an object. The number 12 is an
object, the string “Hello, world” is an object, a list is an object that can hold other
objects, and so on. You’ve been using objects all along and may not even realize it.
An object consists of:
• State: It is represented by the attributes of an object. It also reflects the
properties of an object.
• Behavior: It is represented by the methods of an object. It also reflects the
response of an object to other objects.

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-28
PROGRAMMING WITH PYTHON

• Identity: It gives a unique name to an object and enables one object to


interact with other objects.
To understand the state, behavior, and identity let us take the example of the class
dog (explained above).
• The identity can be considered as the name of the dog.
• State or Attributes can be considered as the breed, age, or color of the
dog.
• The behavior can be considered as to whether the dog is eating or
sleeping.
Creating an Object
This will create an object named obj of the class Dog defined above. Before diving
deep into objects and classes let us understand some basic keywords that will we
used while working with objects and classes.

The Python self


1. Class methods must have an extra first parameter in the method
definition. We do not give a value for this parameter when we call the
method, Python provides it
2. If we have a method that takes no arguments, then we still have to have
one argument.
3. This is similar to this pointer in C++ and this reference in Java. When we
call a method of this object as myobject.method(arg1, arg2), this is
automatically converted by Python into MyClass.method(myobject, arg1,
arg2) – this is all the special self is about.
Note: For more information, refer to self in the Python class
The Python __init__ Method
The __init__ method is similar to constructors in C++ and Java. It is run as soon as
an object of a class is instantiated. The method is useful to do any initialization you
want to do with your object. Now let us define a class and create some objects
using the self and __init__ method.
Creating a class and object with class and instance attributes

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-29
PROGRAMMING WITH PYTHON

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-30
PROGRAMMING WITH PYTHON

print("My name is {}".format(Tommy.name))


Output
Rodger is a mammal
Tommy is also a mammal
My name is Rodger
My name is Tommy

Creating Classes and objects with methods Here,


The Dog class is defined with two attributes:
• attr1 is a class attribute set to the value “mammal”. Class attributes are
shared by all instances of the class.
• __init__ is a special method (constructor) that initializes an instance of
the Dog class. It takes two parameters: self (referring to the instance
being created) and name (representing the name of the dog). The name
parameter is used to assign a name attribute to each instance of Dog. The
speak method is defined within the Dog class. This method prints a string
that includes the name of the dog instance.
The driver code starts by creating two instances of the Dog class: Rodger and
Tommy. The __init__ method is called for each instance to initialize their name
attributes with the provided names. The speak method is called in both instances
(Rodger.speak() and Tommy.speak()), causing each dog to print a statement with
its name.

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-31
PROGRAMMING WITH PYTHON

Output
My name is Rodger
My name is Tommy

Note: For more information, refer to Python Classes and Objects


Python Inheritance
Inheritance is the capability of one class to derive or inherit the properties from
another class. The class that derives properties is called the derived class or child
class and the class from which the properties are being derived is called the base
class or parent class. The benefits of inheritance are:
• It represents real-world relationships well.
• It provides the reusability of a code. We don’t have to write the same
code again and again. Also, it allows us to add more features to a class
without modifying it.
• It is transitive in nature, which means that if class B inherits from
another class A, then all the subclasses of B would automatically inherit
from class A.

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-32
PROGRAMMING WITH PYTHON

Types of Inheritance
• Single Inheritance: Single-level inheritance enables a derived class to
inherit characteristics from a single-parent class.
• Multilevel Inheritance: Multi-level inheritance enables a derived class to
inherit properties from an immediate parent class which in turn inherits
properties from his parent class.
• Hierarchical Inheritance: Hierarchical-level inheritance enables more
than one derived class to inherit properties from a parent class.
• Multiple Inheritance: Multiple-level inheritance enables one derived
class to inherit properties from more than one base class. Inheritance in
Python
In the above article, we have created two classes i.e. Person (parent class) and
Employee (Child Class). The Employee class inherits from the Person class. We
can use the methods of the person class through the employee class as seen in the
display function in the above code. A child class can also modify the behavior of
the parent class as seen through the details() method.

Python3

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-33
PROGRAMMING WITH PYTHON

self.name = name
self.idnumber = idnumber def
display(self):
print(self.name) print(self.idnumber)
def details(self):
print("My name is {}".format(self.name))
print("IdNumber: {}".format(self.idnumber))
# child class class Employee(Person): def __init__(self,
name, idnumber, salary, post): self.salary = salary
self.post = post
# invoking the __init__ of the parent class
Person.__init__(self, name, idnumber)
def details(self):
print("My name is {}".format(self.name))
print("IdNumber: {}".format(self.idnumber))
print("Post: {}".format(self.post))

# creation of an object variable or an instance a =


Employee('Rahul', 886012, 200000, "Intern") #
calling a function of the class Person using # its
instance a.display() a.details()

Output Rahul
886012
My name is Rahul
IdNumber: 886012
Post: Intern
Note: For more information, refer to our Inheritance in Python tutorial

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-34
PROGRAMMING WITH PYTHON

Polymorphism simply means having many forms. For example, we need to


determine if the given species of birds fly or not, using polymorphism we can do this
using a single function.
Polymorphism in Python
This code demonstrates the concept of inheritance and method overriding in Python
classes. It shows how subclasses can override methods defined in their parent class to
provide specific behavior while still inheriting other methods from the parent class.

There are many types of birds.


Most of the birds can fly but some cannot.
There are many types of birds.
Sparrows can fly.

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-35
PROGRAMMING WITH PYTHON

There are many types of birds.


Ostriches cannot fly.
Note: For more information, refer to our Polymorphism in Python
Tutorial. Python Encapsulation
Encapsulation is one of the fundamental concepts in object-oriented programming
(OOP). It describes the idea of wrapping data and the methods that work on data
within one unit. This puts restrictions on accessing variables and methods directly
and can prevent the accidental modification of data. To prevent accidental change, an
object’s variable can only be changed by an object’s method. Those types of
variables are known as private variables.
A class is an example of encapsulation as it encapsulates all the data that is member
functions, variables, etc.

Encapsulation in Python
In the above example, we have created the c variable as the private attribute. We
cannot even access this attribute directly and can’t even change its value.

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-36
PROGRAMMING WITH PYTHON

print(obj1.a)
# Uncommenting print(obj1.c) will
# raise an AttributeError

# Uncommenting obj2 = Derived() will


# also raise an AtrributeError as
# private member of base class
# is called inside derived class
Output
GeeksforGeeks
Note: for more information, refer to our Encapsulation in Python Tutorial.

Data Abstraction

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-37
PROGRAMMING WITH PYTHON

It hides unnecessary code details from the user. Also, when we do not want
to give out sensitive parts of our code implementation and this is where data
abstraction came.
Data Abstraction in Python can be achieved by creating abstract classes.
Object Oriented Programming in Python | Set 2 (Data Hiding and Object Printing)

Don't miss your chance to ride the wave of the data revolution! Every industry is
scaling new heights by tapping into the power of data. Sharpen your skills, become a
part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and
Data Science Program by GeeksforGeeks and stay ahead of the curve.

Python SQLite – Connecting to Database



In this article, we’ll discuss how to connect to an SQLite Database using the sqlite3
••
module in Python.
Connecting to the Database
Connecting to the SQLite Database can be established using the connect() method,
passing the name of the database to be accessed as a parameter. If that database does
not exist, then it’ll be created. sqliteConnection = sqlite3.connect('sql.db')
But what if you want to execute some queries after the connection is being made.
For that, a cursor has to be created using the cursor() method on the connection
instance, which will execute our SQL queries. cursor = sqliteConnection.cursor()
print('DB Init')
The SQL query to be executed can be written in form of a string, and then executed
by calling the execute() method on the cursor object. Then, the result can be fetched
from the server by using the fetchall() method, which in this case, is the SQLite
Version Number.

Example: import
sqlite3 try:

# Connect to DB and create a cursor


sqliteConnection = sqlite3.connect('sql.db') cursor

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-38
PROGRAMMING WITH PYTHON

= sqliteConnection.cursor() print('DB Init')


# Write a query and execute it with cursor
query = 'select sqlite_version();'
cursor.execute(query)
# Fetch and output result result = cursor.fetchall()
print('SQLite Version is {}'.format(result))
# Close the cursor cursor.close()
# Handle errors except
sqlite3.Error as error:
print('Error occurred - ', error)

# Close DB Connection irrespective of success


# or failure finally: if sqliteConnection:
sqliteConnection.close() print('SQLite
Connection closed')

Output:

Designing GUI applications Using PyQt in Python

Building GUI applications using the•• PYQT designer tool is comparatively less
timeconsuming than code the widgets. It is one of the fastest and easiest ways to
create GUIs.
The normal approach is to write the code even for the widgets and for the
functionalities as well. But using Qt-designer, one can simply drag and drop the
widgets, which comes very useful while developing big-scale applications.
Installation of PyQt5 :

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-39
PROGRAMMING WITH PYTHON

• For Linux : sudo apt-get install


python3-pyqt5
• For Windows : pip install
pyqt5 pip install pyqt5-tools
Let’s create a signup form using the QT designer tool. No code is required for
creating forms, buttons, text boxes, etc! It is a rather drag and drops environment.
So, using PyQt is a lot simpler than Tkinter

Next

FINAL PROJECT
PROFILE OF THE PROBLEM Create a Fantasy Cricket game in Python. The
game should have all the features displayed in the mock-up screens in the
scenario. To calculate the points for each player, we can use rules similar to the
sample rules displayed below.
Sample of Rules
Bazng
● 1 point for 2 runs scored

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-40
PROGRAMMING WITH PYTHON

● Addi)onal 5 points for half century

● Addi)onal 10 points for century

● 2 points for strike rate (runs/balls faced) of 80-100

● Addi)onal 4 points for strike rate>100

● 1 point for hizng a boundary (four) and 2 points for over boundary (six)
Bowling
● 10 points for each wicket

● Addi)onal 5 points for three wickets per innings

● Addi)onal 10 points for 5 wickets or more in innings

● 4 points for economy rate (runs given per over) between 3.5 and 4.5

● 7 points for economy rate between 2 and 3.5

● 10 points for economy rate less than 2


Fielding
● 10 points each for catch/stumping/run out

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-41
PROGRAMMING WITH PYTHON

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-42
PROGRAMMING WITH PYTHON

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-43
PROGRAMMING WITH PYTHON

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-44
PROGRAMMING WITH PYTHON

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-45
PROGRAMMING WITH PYTHON

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-46
PROGRAMMING WITH PYTHON

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-47
PROGRAMMING WITH PYTHON

SOURCE CODE
def menu(self,ac)on): txt=(ac)on.text())

if txt=='NEW TEAM':
self.bat=0
self.bow=0
self.ar=0 self.wk=0

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-48
PROGRAMMING WITH PYTHON

self.avl=1000
self.used=0
self.list1.clear()
self.list2.clear()
text,
ok=QtWidget.QInp
utDialog.getText(M
ainWindow,"team",
"enter name of team")
if
ok: self.t7.setText(str(text))

self.show() if
txt=='SAVE Team':
count=self.list2.count()
selected="" for i in range(count):

selected+=self.list2.item.text() if
i<count:
selected+=","
self.saveteam(self.t7.text(),selected,self.used)

if txt=='OPEN TEAM':
self.bat=0
self.bow=0 self.ar=0
self.wk=0
self.avl=1000
self.used=0
self.list1.clear()
self.list2.clear()

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-49
PROGRAMMING WITH PYTHON

self.show()
self.openteam()

if txt=='EVALUATE TEAM': from


dlgscore import ui_Dialog

def saveteam(self,nm,ply,val): if self.bat+self.bow+self.ar+self.wk!=1:


self.showdlg("Isufficient players")
return
sql="INSERT INTO
TEAMS(NAME,PLAYER,VALUE) VALUES
('"+NM+"','"+PLY+"','"+STR(VAL)
+"')

try:
cur=conn.excute(sql)
self.showdlg("team save
succesfully")
conn.commit() except:
self.showglg("error in opera)on")
conn.rollback() def
showdlg(self,msg):
Dialog=QtWidgets.QMessageBox()
Dialog.setText(msg)
Dialog.setWindowTitle("Dream Team selector")

ret=Dialog.exec()
if
_name=="main_":

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-50
PROGRAMMING WITH PYTHON

import sqlite3 conn =


sqlit3.connect('fantasty.db') import
sys app =
Qtwidgets.QMainWindow() ui =
ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_()) def show(self):
self.t1.setText(str(self.bat))
self.t2.setText(str(self.bow))
self.t3.setText(str(self.wk)) self.t4.setText(str(self.ar))
self.t5.setText(str(self.avl))
self.t6.setText(str(self.used)) def criteria(self,ctgr,item):
msg='' if ctgr=="BAT" and
self.bat>=5:msg="batsmennotmorethan 5" if
ctgr=="BWL" and
self.bwl>=5:msg="bowlersnotmorethan 5" if
ctgr=="AR" and
self.ar>=5:msg="allroundnotmorethan 3" if
ctgr=="WK" and
self.wk>=5:msg="wickeepenotmorethan 1"
if msg!='': self.showdlg(msg) return
False if ctgr=="BAT":self.bat+=1 if
ctgr=="BWL":self.bwl+=1 if
ctgr=="AR":self.ar+=1 if
ctgr=="WK":self.wk+=1 sql="SELECT
VALUE

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-51
PROGRAMMING WITH PYTHON

from stats where player='"+item.text()+"'"


cur=conn.execte(sql) row=cur.fetchone()
self.avl=int(row[0]) self.used+=int(row[0]) return True
def calculate(self): import sqlite3 conn =
sqlite3.connect('fantasy.db')
team=self.cb0.currentText() self.lwl.clear()
sql1="select players,value from teams where
name='"+team+"'" cur=conn.excute(sql1)
row=cur.fetchone() selected=row[0],split(',')
self.lw1.additems(selected) teame1=0
self.lw2.clear() match=self.cb1.currentText() for
i in range(self.lw1.count()):
e1,batscore,bowlscore,fieldscore=0,0,0,0
nm=self.lw1item(i).text()
cursor=conn.excute("select" from "+match+" where
player='"+nm+"'") row=cursor.fetchone() batscore=80
if batscore>=50; batscore+=5 if batscore>=100; batscore+=10
if row[1]>0:
sr=row[1]/row[2] if sr>80 and sr<100: batscore+=2 if
sr>100:batscore+=4 batscore=batscore+row[3]
batscore=batscore+2*row[4] bowlscore=row[8]*10 if
row[8]>3:
bowlscore=bowlscore+5 if row[8]>5:
bowlscore=bowlscore=bowlscore+10
if row[7]>0: er=6*row[7]/row[5]
if er<2:
bowlscore=bowlscore+10 if er<2 and er<=3.5: bowlscore=bowlscore+7
if er<3.5 and er<=4.5:

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-52
PROGRAMMING WITH PYTHON

bowlscore=bowlscore+4
fieldscore=(row[9]+row[10]+row[11])*10
CONCLUSION
This course has been an excellent and rewarding experience. I can conclude that
there have been a lot I’ve learnt from my work at there search centre. Needless to
say, the technical aspects of the work I’ve done are not flaw less and could be
improved provided enough )me. As someone with no prior experience in python .
whatsoever I believe my )me spent in research and discovering new languages was
well worth it and contributed to finding an acceptable solu)on to an important aspect
of web design and development. Two main things that I’ve learned the importance of
are )me-management skills and self-mo)va)on. Although I have oien stumbled upon
these problems at University, they had to be approached differently in a working
environment.

SRI VENKATESWARA COLLEGE OF ENGINEERING & TECHNOLOGY (AUTONOMOUS), CHITTOOR


PAGE-53
PROGRAMMING WITH
PYTHON

REFERENCE

All Content used in this report is from


https://www.simplilearn.com/
https://www.wikipedia.org/
https://towardsdatascience.com/
https://www.expertsystem.com/
https://www.coursera.org/
https://www.edureka.co/
https://subhadipml.tech/
https://www.forbes.com/
https://medium.com/
https://www.google.com/ All
Pictures are from
https://www.simplilearn.com/
https://www.google.com/
https://www.wikipedia.org/
https://www.youtube.com/ https://www.edureka.co/
Book I referred are
Hands-on Machine Learning with Scikit-learn & Tensorflow By
Aurelien Geron Python Machine Learning by Sebastian Raschka

SRI VENKATESWARA COLLEGE OF


ENGINEERING &
TECHNOLOGY (AUTONOMOUS), CHITTOOR
PAGE-42

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy