0% found this document useful (0 votes)
11 views

Unit 1 PPT PDF Applied Programing S01 12

The document outlines the Applied Programming course (18ECS301J) taught by Dr. V. Sumitra and Dr. S. Sunithamani, focusing on Python programming. It covers topics such as Python syntax, data types, control flow statements, and the installation of necessary software. The document also highlights the advantages of using Python, its applications in various domains, and provides examples of programming concepts and error handling.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Unit 1 PPT PDF Applied Programing S01 12

The document outlines the Applied Programming course (18ECS301J) taught by Dr. V. Sumitra and Dr. S. Sunithamani, focusing on Python programming. It covers topics such as Python syntax, data types, control flow statements, and the installation of necessary software. The document also highlights the advantages of using Python, its applications in various domains, and provides examples of programming concepts and error handling.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 128

18ECS301J

Applied Programming

Course Instructor:
Dr.V.Sumitra
Dr.S.Sunithamani

18ECS301J-Applied Programming 1
18ECS301J
Applied Programming
Unit 1
Session 1

18ECS301J-Applied Programming 2
18ECS301J Applied Programming

18ECS301J-Applied Programming 3
18ECS301J Applied Programming
Session plan-Unit 1(12 hrs)

18ECS301J-Applied Programming 4
18ECS301J Applied Programming

18ECS301J-Applied Programming 5
18ECS301J Applied Programming

18ECS301J-Applied Programming 6
Unit I Learning Objectives
Introduction, Types and Operation
• Introduction to Python,

• Python Interpreter and its working, Syntax and Semantics

• Data Types, Assignments and Expressions

• Control Flow Statements, Sequences-

• Lists, Dictionaries,

• Tuples and files

• Functions , Lambda expressions

18ECS301J-Applied Programming 7
Required software
• Python Version 2.7 and above: http://python.org
• Install Anaconda Navigator and Launch Jupyter notebook
• Numerical Python (NumPy): http://numpy.org
• Matplotlib for plotting: http://matplotlib.org
• Ipython for interactive computing: http://ipython.org
• Scitools for addons to NumPy: http://code.google.com/scitools

18ECS301J-Applied Programming 8
Installation
• Installing Anaconda on windows
• https://problemsolvingwithpython.com/01-Orientation/01.03-Installing-Anaconda-on-Windows/

18ECS301J-Applied Programming 9
Challenges faced with raw data
• Data quality does not
conform to set standards
• Data integration is a
complex task
• Data is distributed into large
clusters which are difficult
to integrate and analyze.
• Unstructructured and
semistructured data are
hard to analyze.

18ECS301J-Applied Programming 10
Purpose of Python
• Python deals with each stage of data analytics efficiently
by applying different libraries and packages.

18ECS301J-Applied Programming 11
Python creator Guido van Rossum named it after the BBC
comedy series Monty Python’s Flying Circus. He is a big fan of
Monty Python.

18ECS301J-Applied Programming 12
Why Program?
What is a Program?
“Everybody in this country should learn how to program a computer...
because it teaches you how to think”.- Steve Jobs, 1955-2011.
What is a Program?
• A sequence of instructions to the computer, written in a programming
language, somewhat like English, but very much simpler - and very
much stricter.
• This course teaches Python Program

18ECS301J-Applied Programming 13
Introduction to Python

• Python is a widely used general-purpose, high level programming language.


• It was initially designed by Guido van Rossum in 1991 and developed by
Python Software Foundation.
• It was mainly developed for emphasis on code readability, and its syntax allows
programmers to express concepts in fewer lines of code.
• Python is a programming language that lets you work quickly and integrate
systems more efficiently.

18ECS301J-Applied Programming 14
Introduction to Python
Why do people use Python?
The primary factors cited by Python users seem to be these:
• Software quality
• Python code is designed to be readable, and hence reusable and maintainable—much more so than traditional
scripting languages.
• Developer productivity
• Python boosts developer productivity many times beyond compiled or statically typed languages such as C, C++, and
Java.
• Python code is typically one-third to one-fifth the size of equivalent C++ or Java code.
• That means there is less to type, 3 less to debug, and less to maintain after the fact.
• Program portability
• Most Python programs run unchanged on all major computer platforms.
• Porting Python code between Linux and Windows, for example, is usually just a matter of copying a script’s code
between machines
• Support libraries
• Python comes with a large collection of prebuilt and portable functionality, known as the standard library.
• This library supports an array of application-level programming tasks, from text pattern matching to network scripting.
• Component integration
• Python scripts can easily communicate with other parts of an application, using a variety of integration mechanisms.
• Such integrations allow Python to be used as a product customization and extension tool.
• Enjoyment
• Because of Python’s ease of use and built-in toolset, it can make the act of programming more pleasure than chore.
18ECS301J-Applied Programming 15
Introduction to Python

Who use Python?


Google, Industrial Light & Magic, EVE Online, Jet Propulsion Labs, Maya, ESRI, and
many more.
Almost every organization doing software development uses Python in some fashion,
whether for long-term strategic product development or for short-term tactical tasks
such as testing and system administration.

18ECS301J-Applied Programming 16
Introduction to Python

Gaming, Images, Serial Ports, XML, Robots, and More


Python is commonly applied in more domains than can be mentioned here. For example,
you can do:
• Game programming and multimedia in Python with the pygame system
• Serial port communication on Windows, Linux, and more with the PySerial extension
• Image processing with PIL, PyOpenGL, Blender, Maya, and others
• Robot control programming with the PyRo toolkit
• XML parsing with the xml library package, the xmlrpclib module, and third-party
extensions
• Artificial intelligence programming with neural network simulators and expert system
shells
• Natural language analysis with the NLTK packag

18ECS301J-Applied Programming 17
Introduction to Python
Technical strengths of Python?
1. Python is object-oriented Structure supports such concepts as polymorphism, operation overloading and
multiple inheritance.
2. Indentation Indentation is one of the greatest feature in python
3. It’s free (open source) Downloading python and installing python is free and easy
4. It’s Powerful
• Dynamic typing Built-in types and tools
• Library utilities Third party utilities (e.g. Numeric, NumPy, sciPy)
• Automatic memory management
5. It’s Portable
• Python runs virtually every major platform used today
• As long as you have a compaitable python interpreter installed, python programs will run in exactly the same manner,
irrespective of platform.
6. It’s easy to use and learn
• No intermediate compile
• Python Programs are compiled automatically to an intermediate form called byte code, which the interpreter then reads.
• This gives python the development speed of an interpreter without the performance loss inherent in purely interpreted
languages.
• Structure and syntax are pretty intuitive and easy to grasp.
7. Interpreted Language Python is processed at runtime by python Interpreter
8. Interactive Programming Language Users can interact with the python interpreter directly for writing the
programs
9. Straight forward syntax The formation of python syntax is simple and straight forward which also makes it
popular

18ECS301J-Applied Programming 18
Frequently used terms:

Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html

18ECS301J-Applied Programming 19
Operating System
• An operating system (OS) is a set of programs managing hardware
and software resources on a computer

18ECS301J-Applied Programming 20
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
18ECS301J Applied Programming

Summary:
• Introduction to python.
• What are the six main reasons that people choose to use Python.
• List few notable companies or organizations using Python today.
• Why might you not want to use Python in an application?
• What can you do with Python?
• Installation of python software.

18ECS301J-Applied Programming 21
Thank you

18ECS301J-Applied Programming 22
18ECS301J-Applied Programming 23
18ECS301J
Applied Programming
Unit 1
Session 2

18ECS301J-Applied Programming 24
Data Types

18ECS301J-Applied Programming 25
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
• A program consists of statements

• Syntax is the exact specification of instructions to the computer

18ECS301J-Applied Programming 26
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Example program

18ECS301J-Applied Programming 27
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Illegal Variable Names
• Program files can have a freely chosen name, but stay away
from names that coincide with keywords or module names in
Python.
• For instance, do not use
math.py time.py random.py
os.py sys.py, while.py
for.py if.py class.py
def.py
18ECS301J-Applied Programming 28
printf syntax

18ECS301J-Applied Programming 29
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
printf syntax

18ECS301J-Applied Programming 30
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Examples on different printf formats

18ECS301J-Applied Programming 31
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
• A program takes some known input data and computes
some output data

• Objects: Python interprets the number 21 on the right-hand side of the


assignment as an integer and creates an int (for integer) object holding the value
21. The variable C acts as a name for this int object

18ECS301J-Applied Programming 32
Answer?????
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
The error is caused by (unintended) integer division

18ECS301J-Applied Programming 33
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Everything in Python is an Object

18ECS301J-Applied Programming 34
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Arithmetic expressions

18ECS301J-Applied Programming 35
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Using standard Mathematical modules

18ECS301J-Applied Programming 36
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Using standard Mathematical modules

18ECS301J-Applied Programming 37
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Rounding Errors

18ECS301J-Applied Programming 38
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Type Conversion

18ECS301J-Applied Programming 39
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
support for complex numbers

18ECS301J-Applied Programming 40
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Symbolic Computing

18ECS301J-Applied Programming 41
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Interactive Computing
• The environments where you work interactively with programming
are commonly known as Python shells.
• The simplest Python shell is invoked by just typing python at the
command line in a terminal window.

18ECS301J-Applied Programming 42
Let’s find out
why the following programs do not work
C=A+B
A=3
B=2
print C
x=1
Print ‘sin(%g)=%g’ % (x, sin(x))

18ECS301J-Applied Programming 43
Corrected code

A=3
B=2
C=A+B
print(C)

Corrected code

from math import sin


x=1
print('sin(%g)=%g' % (x, sin(x)))
18ECS301J-Applied Programming 44
Find errors in the following statements
• 1a = 2 • c = 4**3**2**3
• _ = ((c-78564)/c + 32))
• a1 = b
• x=2 • discount = 12%
• AMOUNT = 120.-
• y = X + 4 # is it 6? • amount = 120$
• from Math import tan
• address = [email protected]
• print tan(pi)
• and = duck
• pi = "3.14159’ • class = ’INF1100, gr 2"
• continue_ = x > 0
• print tan(pi)
• rev = fox = True
• Norwegian = [’a human language’]
• true = fox is rev in Norwegian

18ECS301J-Applied Programming 45
Corrected code
• ***************************** ******************************
• from math import tan, pi address = '[email protected]'
and_var = 'duck'
• print(tan(pi))
class_var = "INF1100, gr 2"
• pi = "3.14159" continue_var = x > 0
• print(tan(float(pi))) rev = fox = True
• **************************** Norwegian = ['a human language']
• c = 4 ** 3 ** 2 ** 3 true_var = fox is rev in Norwegian
• _ = ((c - 78564) / c + 32) *******************************
• ****************************
• discount = 0.12 # 12% as a decimal
• AMOUNT = 120.0 # Note: Use a decimal point for floating-
point numbers
• amount = 120.0 # Similar to AMOUNT
• ***************************

18ECS301J-Applied Programming 46
Summary

18ECS301J-Applied Programming 47
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
THANK YOU

18ECS301J-Applied Programming 48
18ECS301J
APPLIED PROGAMMING
Unit 1
Session 5 : User Input and error Handling

18ECS301J-Applied Programming 49
18ECS301J-Applied Programming 50
Session 5
Control Flow Statements Sequences

Hard code Data


• Hardcoding is used in various programming languages and
contexts and is generally used when a fixed value or unit of
data must be used in a program.
• Use of fixed values in control structures, such as conditional
statements or loops, in the source code of a program.

18ECS301J-Applied Programming 51
Hard code Data

18ECS301J-Applied Programming 52
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
How to specify input data

18ECS301J-Applied Programming 53
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Getting input

18ECS301J-Applied Programming 54
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Getting input

18ECS301J-Applied Programming 55
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Python Program
• In concrete perspective, Python programs can be decomposed into
modules, statements, expressions, and objects, as follows:
1. Programs are composed of modules.
2. Modules contain statements.
3. Statements contain expressions.
4. Expressions create and process objects.

18ECS301J-Applied Programming 56
Python Collections (Arrays)
• There are four collection data types in the Python programming
language:

• List is a collection which is ordered and changeable. Allows duplicate


members.
• Tuple is a collection which is ordered and unchangeable. Allows
duplicate members.
• Set is a collection which is unordered, unchangeable, and unindexed.
No duplicate members.
• Dictionary is a collection which is ordered and changeable. No
duplicate members.
18ECS301J-Applied Programming 57
Reading from Command line
• Command line arguments are words written after the program name.

18ECS301J-Applied Programming 58
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Reading from Command line

18ECS301J-Applied Programming 59
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Reading data from file

18ECS301J-Applied Programming 60
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Reading data from file

18ECS301J-Applied Programming 61
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Alternative ways to read a file

18ECS301J-Applied Programming 62
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
File reading Demo

18ECS301J-Applied Programming 63
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
18ECS301J-Applied Programming 64
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Reading a mixture of text and numbers

18ECS301J-Applied Programming 65
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Reading a mixture of text and numbers

18ECS301J-Applied Programming 66
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Complete Program

18ECS301J-Applied Programming 67
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Writing Data to a file

18ECS301J-Applied Programming 68
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Writing a table

18ECS301J-Applied Programming 69
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
What is a file?

18ECS301J-Applied Programming 70
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Wrong Input from User

18ECS301J-Applied Programming 71
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Handle errors at the input

18ECS301J-Applied Programming 72
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
18ECS301J-Applied Programming 73
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Summary of Session 5

18ECS301J-Applied Programming 74
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Summary of session 5
Reading and Writing

18ECS301J-Applied Programming 75
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Practice program
• r: Opens a file for reading only r+: Opens a file for both reading and
writing w: Opens a file for writing only w+: Open a file for writing
and reading. a: Opens a file for appending a+: Opens a file for both
appending and reading.

18ECS301J-Applied Programming 76
18ECE201J
Python and Scientific Python
Unit 1
Session 6 : Making Modules

18ECS301J-Applied Programming 77
Python Program
• In concrete perspective, Python programs can be decomposed into
modules, statements, expressions, and objects, as follows:
1. Programs are composed of modules.
2. Modules contain statements.
3. Statements contain expressions.
4. Expressions create and process objects.

18ECS301J-Applied Programming 78
Making Own Modules

18ECS301J-Applied Programming 79
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Making Own Modules

18ECS301J-Applied Programming 80
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
18ECS301J-Applied Programming 81
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Adding test block in a module

18ECS301J-Applied Programming 82
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Test block in functions

18ECS301J-Applied Programming 83
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
How Python can find new module

18ECS301J-Applied Programming 84
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Example

18ECS301J-Applied Programming 85
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
18ECE201J
Python and Scientific Python
Unit 1
Session 9 : While and for loops,
Lists manipulation, Loops with list indices

18ECS301J-Applied Programming 86
Loops
• Repetitive tasks in a program can be automated by
loops

18ECS301J-Applied Programming 87
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
While Loop

18ECS301J-Applied Programming 88
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
While Loop – Program Flow

18ECS301J-Applied Programming 89
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Boolean expression – T or F

18ECS301J-Applied Programming 90
Lists
• Lists are objects for storing a sequence of things (objects)

18ECS301J-Applied Programming 91
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
List Operations
indexing, append, extend, insert, delete

18ECS301J-Applied Programming 92
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
List Opeations: search

18ECS301J-Applied Programming 93
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
for Loop

18ECS301J-Applied Programming 94
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Making a table with for loop

18ECS301J-Applied Programming 95
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Translate for loop to while loop

18ECS301J-Applied Programming 96
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Mathematical sum using loops

18ECS301J-Applied Programming 97
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Storing Table columns as Lists

18ECS301J-Applied Programming 98
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
for loop with list indices

18ECS301J-Applied Programming 99
Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Change elements in a list

18ECS301J-Applied Programming 100


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
List Comprehension

18ECS301J-Applied Programming 101


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Loops: Use of zip construct

18ECS301J-Applied Programming 102


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
18ECE201J
Python and Scientific Python
Unit 1
Session 10 : Nested loops, functions, lambda functions, if tests

18ECS301J-Applied Programming 103


Nested Lists

18ECS301J-Applied Programming 104


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Table of columns Vs Table of rows

18ECS301J-Applied Programming 105


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Illustration of nested lists
Illustration of table of columns Illustration of table of rows

18ECS301J-Applied Programming 106


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Extracting sublists (slices…)

What does this code snippet do?

18ECS301J-Applied Programming 107


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Example

18ECS301J-Applied Programming 108


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Homework

18ECS301J-Applied Programming 109


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Tuples: Constant Lists

18ECS301J-Applied Programming 110


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Need for Tuples

18ECS301J-Applied Programming 111


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Functions: An important programming
tool

18ECS301J-Applied Programming 112


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Functions: An important programming tool

18ECS301J-Applied Programming 113


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Functions must be called

18ECS301J-Applied Programming 114


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Functions: Example

18ECS301J-Applied Programming 115


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Functions: Example

18ECS301J-Applied Programming 116


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Local Vs Global Variables

18ECS301J-Applied Programming 117


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Home work

18ECS301J-Applied Programming 118


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Function: Python Convention

18ECS301J-Applied Programming 119


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Functions

18ECS301J-Applied Programming 120


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Functions: Example

18ECS301J-Applied Programming 121


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Lambda functions:
compact inline functions

18ECS301J-Applied Programming 122


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
if tests:
for branching the flow of statements

18ECS301J-Applied Programming 123


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
General form of if tests

18ECS301J-Applied Programming 124


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Example on multiple branching
• In line if tests

18ECS301J-Applied Programming 125


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Summary of sessions 9 and 10

18ECS301J-Applied Programming 126


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
Summary of sessions 9 and 10

18ECS301J-Applied Programming 127


Courtesy: https://hplgit.github.io/scipro-primer/slides/index.html
End of UNIT-I

18ECS301J-Applied Programming 128

You might also like