Problem Solving and
Python Programming
Mrs. Anuradha A. Puntambekar
M.E. (Computer)
Formerly Assistant Professor in
P.E.S. Modern College of Engineering, Pune
J. Jayalakshmi
M.E. (CSE)
Professor in CSI College of Engineering,
Ketti, Ooty, The Nilgiris
® TM
TECHNICAL Website : www.technicalpublications.org
PUBLICATIONS
An Up-Thrust for Knowledge https://www.facebook.com/technicalpublications
(i)
,Problem Solving and Python
Programming
Semester - I (Common to All Branches)
First Edition : August 2017
Second Revised Edition : June 2018
ã Copyright with A.A.Puntambekar
All publishing rights (printed and ebook version) reserved with Technical Publications. No part of this book
should be reproduced in any form, Electronic, Mechanical, Photocopy or any information storage and
retrieval system without prior permission in writing, from Technical Publications, Pune.
Published
®
by :
Amit Residency, Office No.1, 412, Shaniwar Peth, Pune - 411030, M.S. INDIA
TM
TECHNICAL Ph.: +91-020-24495496/97, Telefax : +91-020-24495497
PUBLICATIONS Email : Website : www.technicalpublications.org
Printer :
Yogiraj Printers & Binders
S.No. 10/1a, Ghule Industrial Estate, Nanded Village Road,
Tal. : Haveli, Dist. Pune
Price : ` 195 /-
ISBN 978-93-332-1661-6
9 789333 216616 AU 17
9789333216616 [2] (ii)
(ii)
, Preface
The importance of Problem Solving and Python Programming is well known
in various engineering fields. Overwhelming response to our books on various
subjects inspired us to write this book. The book is structured to cover the key aspects
of the subject Problem Solving and Python Programming.
The book uses plain, lucid language to explain fundamentals of this subject. The
book provides logical method of explaining various complicated concepts and
stepwise methods to explain the important topics. Each chapter is well supported with
necessary illustrations, practical examples and solved problems. All chapters in this
book are arranged in a proper sequence that permits each topic to build upon earlier
studies. All care has been taken to make students comfortable in understanding the
basic concepts of this subject.
Representative questions have been added at the beginning of each section to
help the students in picking important points from that section.
The book not only covers the entire scope of the subject but explains the
philosophy of the subject. This makes the understanding of this subject more clear
and makes it more interesting. The book will be very useful not only to the students
but also to the subject teachers. The students have to omit nothing and possibly have
to cover nothing more.
We wish to express our profound thanks to all those who helped in making this
book a reality. Much needed moral support and encouragement is provided on
numerous occasions by our whole family. We wish to thank the Publisher and the
entire team of Technical Publications who have taken immense pain to get this book
in time with quality printing.
Any suggestion for the improvement of the book will be acknowledged and well
appreciated.
Authors
A.A.Puntambekar
J.JayaLakshmi
Dedicated to God.
(iii)
, Syllabus
Problem Solving and Python Programming (GE8151)
Unit - I : Algorithmic Problem Solving
Algorithms, building blocks of algorithms (statements, state, control flow, functions), notation (pseudo
code, flow chart, programming language), algorithmic problem solving, simple strategies for developing
algorithms (iteration, recursion). Illustrative problems : find minimum in a list, insert a card in a list of
sorted cards, guess an integer number in a range, Towers of Hanoi. (Chapter - 1)
Unit - II : Data, Expressions, Statements
Python interpreter and interactive mode; values and types : int, float, boolean, string, and list; variables,
expressions, statements, tuple assignment, precedence of operators, comments; modules and functions,
function definition and use, flow of execution, parameters and arguments; Illustrative programs :
exchange the values of two variables, circulate the values of n variables, distance between two points.
(Chapter - 2)
Unit - III : Control Flow, Functions
Conditionals: Boolean values and operators, conditional (if), alternative (if-else), chained conditional
(if-elif-else); Iteration: state, while, for, break, continue, pass; Fruitful functions : return values,
parameters, local and global scope, function composition, recursion ; Strings : string slices, immutability,
string functions and methods, string module; Lists as arrays. Illustrative programs : square root, gcd,
exponentiation, sum an array of numbers, linear search, binary search. (Chapter - 3)
Unit - IV : Lists, Tuples, Dictionaries
Lists : list operations, list slices, list methods, list loop, mutability, aliasing, cloning lists, list parameters;
Tuples : tuple assignment, tuple as return value; Dictionaries : operations and methods; advanced list
processing - list comprehension; Illustrative programs : selection sort, insertion sort, mergesort,
histogram. (Chapter - 4)
Unit - V : Files, Modules, Packages
Files and exception : text files, reading and writing files, format operator; command line arguments,
errors and exceptions, handling exceptions, modules, packages; Illustrative programs : word count, copy
file. (Chapter - 5)
(iv)
Python Programming
Mrs. Anuradha A. Puntambekar
M.E. (Computer)
Formerly Assistant Professor in
P.E.S. Modern College of Engineering, Pune
J. Jayalakshmi
M.E. (CSE)
Professor in CSI College of Engineering,
Ketti, Ooty, The Nilgiris
® TM
TECHNICAL Website : www.technicalpublications.org
PUBLICATIONS
An Up-Thrust for Knowledge https://www.facebook.com/technicalpublications
(i)
,Problem Solving and Python
Programming
Semester - I (Common to All Branches)
First Edition : August 2017
Second Revised Edition : June 2018
ã Copyright with A.A.Puntambekar
All publishing rights (printed and ebook version) reserved with Technical Publications. No part of this book
should be reproduced in any form, Electronic, Mechanical, Photocopy or any information storage and
retrieval system without prior permission in writing, from Technical Publications, Pune.
Published
®
by :
Amit Residency, Office No.1, 412, Shaniwar Peth, Pune - 411030, M.S. INDIA
TM
TECHNICAL Ph.: +91-020-24495496/97, Telefax : +91-020-24495497
PUBLICATIONS Email : Website : www.technicalpublications.org
Printer :
Yogiraj Printers & Binders
S.No. 10/1a, Ghule Industrial Estate, Nanded Village Road,
Tal. : Haveli, Dist. Pune
Price : ` 195 /-
ISBN 978-93-332-1661-6
9 789333 216616 AU 17
9789333216616 [2] (ii)
(ii)
, Preface
The importance of Problem Solving and Python Programming is well known
in various engineering fields. Overwhelming response to our books on various
subjects inspired us to write this book. The book is structured to cover the key aspects
of the subject Problem Solving and Python Programming.
The book uses plain, lucid language to explain fundamentals of this subject. The
book provides logical method of explaining various complicated concepts and
stepwise methods to explain the important topics. Each chapter is well supported with
necessary illustrations, practical examples and solved problems. All chapters in this
book are arranged in a proper sequence that permits each topic to build upon earlier
studies. All care has been taken to make students comfortable in understanding the
basic concepts of this subject.
Representative questions have been added at the beginning of each section to
help the students in picking important points from that section.
The book not only covers the entire scope of the subject but explains the
philosophy of the subject. This makes the understanding of this subject more clear
and makes it more interesting. The book will be very useful not only to the students
but also to the subject teachers. The students have to omit nothing and possibly have
to cover nothing more.
We wish to express our profound thanks to all those who helped in making this
book a reality. Much needed moral support and encouragement is provided on
numerous occasions by our whole family. We wish to thank the Publisher and the
entire team of Technical Publications who have taken immense pain to get this book
in time with quality printing.
Any suggestion for the improvement of the book will be acknowledged and well
appreciated.
Authors
A.A.Puntambekar
J.JayaLakshmi
Dedicated to God.
(iii)
, Syllabus
Problem Solving and Python Programming (GE8151)
Unit - I : Algorithmic Problem Solving
Algorithms, building blocks of algorithms (statements, state, control flow, functions), notation (pseudo
code, flow chart, programming language), algorithmic problem solving, simple strategies for developing
algorithms (iteration, recursion). Illustrative problems : find minimum in a list, insert a card in a list of
sorted cards, guess an integer number in a range, Towers of Hanoi. (Chapter - 1)
Unit - II : Data, Expressions, Statements
Python interpreter and interactive mode; values and types : int, float, boolean, string, and list; variables,
expressions, statements, tuple assignment, precedence of operators, comments; modules and functions,
function definition and use, flow of execution, parameters and arguments; Illustrative programs :
exchange the values of two variables, circulate the values of n variables, distance between two points.
(Chapter - 2)
Unit - III : Control Flow, Functions
Conditionals: Boolean values and operators, conditional (if), alternative (if-else), chained conditional
(if-elif-else); Iteration: state, while, for, break, continue, pass; Fruitful functions : return values,
parameters, local and global scope, function composition, recursion ; Strings : string slices, immutability,
string functions and methods, string module; Lists as arrays. Illustrative programs : square root, gcd,
exponentiation, sum an array of numbers, linear search, binary search. (Chapter - 3)
Unit - IV : Lists, Tuples, Dictionaries
Lists : list operations, list slices, list methods, list loop, mutability, aliasing, cloning lists, list parameters;
Tuples : tuple assignment, tuple as return value; Dictionaries : operations and methods; advanced list
processing - list comprehension; Illustrative programs : selection sort, insertion sort, mergesort,
histogram. (Chapter - 4)
Unit - V : Files, Modules, Packages
Files and exception : text files, reading and writing files, format operator; command line arguments,
errors and exceptions, handling exceptions, modules, packages; Illustrative programs : word count, copy
file. (Chapter - 5)
(iv)