ebook img

Introduction To Computing And Problem Solving Using Python PDF

336 Pages·2016·3.807 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Introduction To Computing And Problem Solving Using Python

I C P NTRODUCTION TO OMPUTING AND ROBLEM S U P OLVING SING YTHON A A BOUT THE UTHOR E Balagurusamy is presently the Chairman of EBG Foundation, Coimbatore. In the past he has also held the positions of member, Union Public Service Commission, New Delhi and Vice-Chancellor, Anna University, Chennai, Tamil Nadu. He is a teacher, trainer and consultant in the fields of Information Technology and Management. He holds an ME (Hons) in Electrical Engineering and PhD in Systems Engineering from the Indian Institute of Technology, Roorkee, Uttarakhand. His areas of interest include Object-Oriented Software Engineering, E-Governance: Technology Management, Business Process Re-engineering and Total Quality Management. A prolific writer, he has authored a large number of research papers and several books. His best-selling books, among others include: ● Programming in ANSIC, 7/e ● Fundamentals of Computers ● Computing Fundamentals and C Programming ● Programming in C#, 3/e ● Programming in Java, 5/e ● Object-Oriented Programming with C++, 5/e ● Programming in BASIC, 3/e ● Numerical Methods ● Reliability Engineering A recipient of numerous honors and awards, he has been listed in the Directory of Who’s Who of Intellectuals and in the Directory of Distinguished Leaders in Education. I C P NTRODUCTION TO OMPUTING AND ROBLEM S U P OLVING SING YTHON E Balagurusamy Chairman EBG Foundation Coimbatore McGraw Hill Education (India) Private Limited NEW DELHI McGraw Hill Education Offices New Delhi NewYork St Louis SanFrancisco Auckland Bogotá Caracas Kuala Lumpur Lisbon London Madrid Mexico City Milan Montreal San Juan Santiago Singapore Sydney Tokyo Toronto McGraw Hill Education (India) Private Limited Published by McGraw Hill Education (India) Private Limited P-24, Green Park Extension, New Delhi 110 016 Introduction to Computing & Problem Solving using Python, 1e Copyright © 2016by McGraw Hill Education (India) Private Limited. No part of this publication may be reproduced or distributed in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise or stored in a database or retrieval system without the prior written permission of the publishers. The program listings (if any) may be entered, stored and executed in a computer system, but they may not be reproduced for publication. This edition can be exported from India only by the publishers, McGraw Hill Education (India) Private Limited Print Edition: ISBN-13: 978-93-5260-258-2 ISBN-10: 93-5260-258-7 Managing Director: Kaushik Bellani Director—Products, Higher Education and Professional: Vibha Mahajan Specialist-Product Development: Piyush Priyadarshi Head—Production (Higher Education and Professional): Satinder S Baveja Senior Copy Editor: Kritika Lakhera Assistant Manager: Anjali Razdan Assistant General Manager—Product Management: Shalini Jha Manager—Product Management: Kartik Arora General Manager—Production: Rajender P Ghansela Manager—Production:Reji Kumar Information contained in this work has been obtained by McGraw Hill Education (India), from sources believed to be reliable. However, neither McGraw Hill Education (India) nor its authors guarantee the accuracy or completeness of any information published herein, and neither McGraw Hill Education (India) nor its authors shall be responsible for any errors, omissions, or damages arising out of use of this information. This work is published with the understanding that McGraw Hill Education (India) and its authors are supplying information but are not attempting to render engineering or other professional services. If such services are required, the assistance of an appropriate professional should be sought. Typeset at The Composers, 260, C.A. Apt., Paschim Vihar, New Delhi 110 063 and printed at Cover Printer: Visit us at: www.mheducation.co.in C ONTENTS Preface ix Acknowledgements xiii Chapter 1 Introduction to Digital Computer 1 1.1 Introduction 1 1.2 Von Neumann Concept 3 1.3 Storage 6 1.4 Programming Languages 10 1.5 Translators 12 1.6 Hardware and Software 13 1.7 Operating Systems 15 Always Remember 16 Key Terms 16 Review Exercises 17 Multiple Choice Questions 17 Short Questions 19 Answers to Multiple Choice Questions 20 Chapter 2 Problem Solving Strategies 21 2.1 Problem Analysis 21 2.2 Algorithms 22 2.3 Flow Charts 24 2.4 Examples of Algorithms and Flow Charts 28 Always Remember 33 Key Terms 33 Review Exercises 34 Multiple Choice Questions 34 Short Questions 35 Answers to Multiple Choice Questions 35 vi Contents Chapter 3 Introduction toPython 36 3.1 Introduction 36 3.2 Python Overview 36 3.3 Getting Started with Python 37 3.4 Comments 42 3.5 Python Identifiers 42 3.6 Reserved Keywords 43 3.7 Variables 43 3.8 Standard Data Types 45 3.9 Operators 51 3.10 Statement and Expression 61 3.11 String Operations 62 3.12 Boolean Expressions 64 3.13 Control Statements 65 3.14 Iteration – while Statement 71 3.15 Input from Keyboard 73 Always Remember 75 Key Terms 76 Review Exercises 76 Multiple Choice Questions 80 Short Questions 81 Answers to Multiple Choice Questions 81 Chapter 4 Functions 82 4.1 Introduction 82 4.2 Built-in Functions 82 4.3 Composition of Functions 88 4.4 User Defined Functions 89 4.5 Parameters and Arguments 92 4.6 Function Calls 96 4.7 Thereturn Statement 97 4.8 Python Recursive Function 98 4.9 The Anonymous Functions 98 4.10 Writing Python Scripts 100 Always Remember 102 Key Terms 103 Review Exercises 104 Multiple Choice Questions 109 Short Questions 110 Answers to Multiple Choice Questions 111 Contents vii Chapter 5 Strings and Lists 112 5.1 Strings 112 5.2 Lists 124 Always Remember 132 Key Terms 133 Review Exercises 134 Multiple Choice Questions 141 Short Questions 144 Answers to Multiple Choice Questions 147 Chapter 6 Tuples and Dictionaries 148 6.1 Tuples 148 6.2 Dictionaries 159 Always Remember 166 Key Terms 167 Review Exercises 168 Multiple Choice Questions 174 Short Questions 177 Answers to Multiple Choice Questions 179 Chapter 7 Files and Exceptions 180 7.1 Text Files 180 7.2 Directories 190 7.3 Exceptions 192 7.4 Exception with Arguments 198 7.5 User-Defined Exceptions 199 Always Remember 201 Key Terms 202 Review Exercises 203 Multiple Choice Questions 208 Short Questions 210 Answers to Multiple Choice Questions 211 Chapter 8 Classes and Objects 212 8.1 Overview of OOP (Object-Oriented Programming) 212 8.2 Class Definition 213 8.3 Creating Objects 215 8.4 Objects as Arguments 218 8.5 Objects as Return Values 219 8.6 Built-in Class Attributes 220 8.7 Inheritance 221 8.8 Method Overriding 225 8.9 Data Encapsulation 225 viii Contents 8.10 Data Hiding 227 Always Remember 228 Key Terms 229 Review Exercises 230 Multiple Choice Questions 236 Short Questions 238 Answers to Multiple Choice Questions 239 Appendix A: Practice Exercises with Algorithm and Flow Chart 240 Appendix B: Problem Solving Exercises—With Algorithm and Pseudocode 293 Appendix C: Fundamental Standard Library Modules 317 P REFACE Developments in the field of digital electronics and the huge amount of data generated during the last few decades ushered in the second Industrial Revolution which is popularly referred to as the Information Revolution. Information technology played an ever-increasing role in this new revolution. A sound knowledge of how computers work, process and analyze data has, therefore, become indispensable for everyone who seeks employment not only in the area of IT, but also in any other fields. Rightly so, many institutions and universities in India have introduced a subject covering the fundamentals of computation and problem solving with Python for their undergraduate students. This book caters to those needs of the undergraduate students. Why learn Python? Python is a high-level, interpreted, reflective, dynamically typed, open-source, multi-paradigm, and general- purpose programming language. It is quite powerful and easy. It offers no special tools or features that let you do things that you cannot do with other languages, but its elegant design and combination of certain features make Python a pleasure to use. What’s Special in this Book? The book ensures a smooth and successful transition to a skilled expert in Python. This book uses a simple- to-complex and easy-to-learn approach throughout the book. The concept of ‘learning by-solving’ has been stressed in all the chapters of the book. Each feature of Python is treated in-depth followed by a complete program example to illustrate its use. Wherever necessary, concepts are explained pictorially to facilitate better understanding. It presents a contemporary approach to programming, offering a combination of theory and practice. Each of the 8 chapters follow a common structure with a range of learning and assessment tools for instructors and students. SALIENT FEATURES of the Book The salient features of the book include the following: ● Bottom-up approach of explaining concepts has been adopted in the book. x Preface ● Algorithms and flowcharts have been discussed extensively in an appendix. ● Codes with Comments have been provided throughout the book to illustrate the use of various features of Python. ● Supplementary Information and important notes that complement, but stand apart from the text, have been included in special boxes under the head Notes. ● Always Remember consists of important summary points at the end of every chapter to help the readers recollect the topics covered with ease. ● Check Your Understanding helps the readers evaluate their learning after every section within the chapters of the book. ● Important Key Terms within the chapter have been listed at the end. Review Exercises comprising Multiple choice questions along with answer keys, short questions and programming exercises are provided at the chapter end to help readers test their conceptual understanding. Organization of the Book The book spans across eight chapters. The first two chapters introduces the learner to digital computers–the basic structure, programming languages, operating systems, problem solving strategies and conventional introduction to programming. The next six chapters present a more-or-less the conventional introduction to programming. The readers learn about variables, types, statements, conditionals, loops, functions, recursion, classes and inheritance. In all the chapters, first the basic ideas are explained, and then the reader is led through a process of experimentation that helps them find and test the limits of their understanding. Web Supplements The web supplements can be accessed at <http://highered.mheducation.com/sites/9352602587> which contains the following: ● Solution Manual ● Lecture PPTs covering 1. Important standard library (a) argparse (b) csv (c) math (d) os (e) pickle (f) random (g) subprocess 2. How to install third party libraries (a) Using pip (i) Installing pip under Windows and Linux (ii) Using pip to install a package (b) Installing packages from source.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.