Python Session1-2
Python Session1-2
Course Overview
• The Syllabus is framed to get to doing data analysis problems as quickly as possible
and have a series of running examples and exercises about data analysis from the
very beginning.
• Number-oriented examples and exercises have been explained with data oriented
exercises.
• Topics are presented in the order needed to build increasingly sophisticated data
analysis solutions.
• The material is focusing on real-world uses and simple examples of Python for data
analysis including regular expressions for searching and parsing, automating tasks
on your computer, retrieving data across the network, scraping web pages for data,
object-oriented programming, using web services, parsing XML and JSON data,
creating and using databases using Structured Query Language, and visualizing data.
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
Course Duration
Subject code : 18EC646 IA Marks : 40
Course Syllabus
Module 1 : Why should you learn to write programs, Variables, expressions, and statements, Conditional execution,
Functions.
Module 2 : Iterations, Strings, Files
Module 3 : Lists, Dictionaries, Tuples, Regular expressions
Module 4 : Classes and objects, Classes and Functions, Classes and methods
Module 5 : Networked programs, Using Web Services, Using Databases and SQL
References
Text book:
1) Charles R. Severance, “Python for Everybody: Exploring Data Using Python 3”, 1 st Create space Independent publishing
format 2016(Chapter 1-13, 15).
2) Allen B Downey, “Think Python: How to Think Like a Computer Scientist”, 2nd Edition, Green Tea Press 2015(Chapter 15,
16, 17).
Reference Book:
3) Marks Lutz, “Programming Python”, 4th Edition O’Reilly Media 2011, ISBN 13:978-9350232873
4) Wesly J Chun, “Core Python Application Programing”, 3 rd Edition, Pearson Education India 2015. ISBN-13:978-
9332555365.
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
Course Objectives
This course will enable students to
Learn syntax and semantics and create function in Python
Handling strings and Files in Python
Understand Lists, Dictionaries and Regular Expressions in Python
Implement Object –Oriented Programming in Python
Build Web Services Network and Database programs in Python
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
Course Outcomes
After studying this course, students will be able to:
Examine Python syntax and semantics and be fluent in the use of Python flow control and
functions.
Demonstrate proficiency in handling strings and File Systems
Create, run and manipulate Python Programs using core data structures like Lists, Dictionaries
and use Regular Expressions
Interpret the concepts of Object Oriented Programming as used in Python
Implement exemplary applications related to Network Programming, Web Services and
Databases in Python
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
Course Policy
There will be 3 tests
First test will cover the first 2 Modules
Second will cover the next 1.5 Modules
Third will cover the remaining 1.5 Modules
Each Test is for 30 marks
There will be assignments (Collaborative Learning) on each unit. Five Assignment. Each carries
10 marks
Average of all three Test plus the average of all five assignment is considered for the Final
internal marks
Monday, June 5
, 2023
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
Monday, June 5
, 2023
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
Monday, June 5
, 2023
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
Module 1
• Topic 1: Why should you learn to write programs
• Topic 2: Variables, expressions and statements
• Topic 3: Conditional execution
• Topic 4: Functions
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
Why should
• Writing you (or
programs learn to write programs?
programming) is a very creative and rewarding activity. You can write programs
for many reasons, ranging from making your living to solving a difficult data analysis problem to
having fun to helping someone else solve a problem.
• We are surrounded in our daily lives with computers ranging from laptops to cell phones. We can
think of these computers as our “personal assistants” who can take care of many things on our
behalf.
• Programmers add an operating system and a set of applications to the hardware and we end up with
a Personal Digital Assistant that is quite helpful and capable of helping us do many different things.
• Our computers are fast and have vast amounts of memory and could be very helpful to us if we only
knew the language to speak to explain to the computer what we would like it to “do next”. If we
knew this language, we could tell the computer to do tasks on our behalf that were repetitive.
Interestingly, the kinds of things computers can do best are often the kinds of things that we humans
find boring and mind-numbing.
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
1.1 Creativity
• Building and
useful, motivation
elegant, and clever programs for others to use is a very creative activity. Your
computer or Personal Digital Assistant (PDA) usually contains many different programs from
many different groups of programmers, each competing for your attention and interest.
• They try their best to meet your needs and give you a great user experience in the process.
In some situations, when you choose a piece of software, the programmers are directly
compensated because of your choice.
• For now, our primary motivation is not to make money or please end users, but instead for
us to be more productive in handling the data and information that we will encounter in our
lives. When you first start, you will be both the programmer and the end user of your
programs. As you gain skill as a programmer and programming feels more creative to you,
your thoughts may turn toward developing programs for others.
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
The >>> prompt is the Python interpreter’s way of asking you, “What do you want me to do next?”
Python is ready to have a conversation with you. All you have to know is how to speak the Python
language.
>>> I come in peace, please take me to your leader
File "", line 1
I come in peace, please take me to your leader
^ SyntaxError: invalid syntax
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
The following are part of every programming language from machine language up to the high-
level languages.
Input: Get data from the “outside world”. This might be reading data from a file, or even some
kind of sensor like a microphone or GPS. In our initial programs, our input will come from the
user typing data on the keyboard.
Output: Display the results of the program on a screen or store them in a file or perhaps write
them to a device like a speaker to play music or speak text.
Sequential execution: Perform statements one after another in the order they are
encountered in the script.
Conditional execution: Check for certain conditions and then execute or skip a sequence of
statements.
Repeated execution: Perform some set of statements repeatedly, usually with some variation.
Reuse: Write a set of instructions once and give them a name and then reuse those
instructions as needed throughout your program.
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
1.11 Debugging
reading Examine your code, read it back to yourself, and check that it says what
you meant to say.
running Experiment by making changes and running different versions. Often if
you display the right thing at the right place in the program, the problem
becomes obvious, but sometimes you have to spend some time to build
scaffolding.
ruminating Take some time to think! What kind of error is it: syntax, runtime,
semantic? What information can you get from the error messages, or from the
output of the program? What kind of error could cause the problem you’re
seeing? What did you change last, before the problem appeared?
retreating At some point, the best thing to do is back off, undoing recent
changes, until you get back to a program that works and that you understand.
Then you can start rebuilding.
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
Exercises
Exercise 1: What is the function of the secondary memory in a
computer?
a) Execute all of the computation and logic of the program
b) Retrieve web pages over the Internet
c) Store information for the long term, even beyond a power
cycle
d) Take input from the user
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
Exercises
Exercise 2: What is a program?
Exercise 3: What is the difference between a compiler and an interpreter?
Exercise 4: Which of the following contains “machine code”?
a) The Python interpreter
b) The keyboard
c) Python source file
d) A word processing document
Exercise 5: What is wrong with the following code:
>>> primt 'Hello world!'
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
Exercises
Exercise 6: Where in the computer is a variable such as “x” stored after the following Python line finishes?
x = 123
a) Central processing unit
b) Main Memory
c) Secondary Memory
d) Input Devices
e) Output Devices
Exercise 7: What will the following program print out:
x = 43
x=x+1
print(x)
f) 43
g) 44
h) x+1
i) Error because x = x + 1 is not possible mathematically
VIDYA VIKAS INSTITUTE
Department of Electronics & Communication Engineering OF ENGINEERING &
TECHNOLOGY
Exercises
Exercise 8: Explain each of the following using an example of a human capability:
(1) Central processing unit,
(2) Main Memory,
(3) Secondary Memory,
(4) Input Device, and
(5) Output Device.
For example, “What is the human equivalent to a Central Processing Unit”?
Exercise 9: How do you fix a “Syntax Error”?