Programming and problem solving with Python
β Scribed by Ashok Namdev Kamthane, Amit Ashok Kamthane
- Publisher
- McGraw Hill Education (India)
- Year
- 2018
- Tongue
- English
- Leaves
- 426
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
This book aims at providing students thorough knowhow of Python programming language. It will familiarize them with the concepts of Python programming, its application in programming as well as advantages and disadvantages over other programming languages. The book covers all the fundamental and theoretical concepts of Python comprehensively. Apart from touching upon the concepts of Python programming, equal weightage in given on the implementation of these concepts in writing efficient python codes and solve problems using the same.
β¦ Table of Contents
About the Authors
Preface
Use of Python in Engineering Domains
Organization of the Book
Online Learning Centre
Publisherβs Note
Visual Wakthrough
Acknowledgements
Contents
1. Introduction to Computer and Python Programming
Learning Outcomes
Chapter Outline
1.1 Introduction
1.2 What is a Computer?
1.2.1 Input/Output (I/O) Unit
1.2.2 Central Processing Unit (CPU)
1.2.3 Memory Unit
1.3 Overview of Programming Languages
1.3.1 Machine Language
1.3.2 Assembly Language
1.3.3 High-level Language
1.4 History of Python
1.4.1 Why Python?
1.4.2 Installing Python in Windows
1.4.3 Starting Python in Different Execution Modes
1.5 Installing Python in Ubuntu
1.6 Executing Python Programs
1.6.1 Writing the First Python Program in Script Mode
1.7 Commenting in Python
1.8 Internal Working of Python
1.9 Python Implementations
1.9.1 Jython
1.9.2 IronPython
1.9.3 Stackless Python
1.9.4 PyPy
Summary
Key Terms
Review Questions
Programming Assignments
2. Basics of Python Programming
Chapter Outline
Learning Outcomes
2.1 Introduction
2.2 Python Character Set
2.3 Token
2.3.1 Literal
2.3.2 Value and Type on Literals
2.3.3 Keywords
2.3.4 Operator
2.3.5 Delimiter
2.3.6 Identifier/variable
2.4 Python Core Data Type
2.4.1 Integer
2.4.2 Floating Point Number
2.4.3 Complex Number
2.4.4 Boolean Type
2.4.5 String Type
2.5 The print() Function
2.5.1 The Print() function with end Argument
2.6 Assigning Value to a Variable
2.6.1 More on Assigning Values to Variables
2.6.2 Scope of a Variable
2.7 Multiple Assignments
2.8 Writing Simple Programs in Python
2.9 The input() Function
2.9.1 Reading String from the Console
2.10 The eval() Function
2.10.1 Apply eval() to input() Function
2.11 Formatting Number and Strings
2.11.1 Formatting Floating Point Numbers
2.11.2 Justifying Format
2.11.3 Integer Formatting
2.11.4 Formatting String
2.11.5 Formatting as a Percentage
2.11.6 Formatting Scientific Notation
2.12 Python Inbuilt Functions
2.12.1 the ord and chr Functions
Summary
Key Terms
Review Questions
Programming Assignments
3. Operators and Expressions
Chapter Outline
Learning Outcomes
3.1 Introduction
3.2 Operators and Expressions
3.3 Arithmetic Operators
3.3.1 Unary Operators
3.3.2 Binary Operators
3.4 Operator Precedence and Associativity
3.4.1 Example of Operator Precedence
3.4.2 Associativity
3.5 Changing Precedence and Associativity of Arithmetic Operators
3.6 Translating Mathematical Formulae into Equivalent Python Expressions
3.7 Bitwise Operator
3.7.1 The Bitwise AND (&) Operator
3.7.2 The Bitwise OR (|) Operator
3.7.3 The Bitwise XOR (^) Operator
3.7.4 The Right Shift (>>) Operator
3.7.5 The Left Shift (<<) Operator
3.8 The Compound Assignment Operator
Mini Project Goods Service Tax (GST) Calculator
Summary
Key Terms
Review Questions
Programming Assignments
4. Decision Statements
Chapter Outline
Learning Outcomes
4.1 Introduction
4.2 Boolean Type
4.3 Boolean Operators
4.3.1 The not Operator
4.3.2 The and Operator
4.3.3 The or Operator
4.4 Using Numbers with Boolean Operators
4.5 Using String with Boolean Operators
4.6 Boolean Expressions and Relational Operators
4.7 Decision Making Statements
4.7.1 the if Statements
4.7.2 the if-else Statement
4.7.3 Nested if Statements
4.7.4 Multi-way if-elif-else Statements
4.8 Conditional Expressions
Mini Project Finding the Number of Days in a Month
Summary
Key Terms
Review Questions
Programming Assignments
5. Loop Control Statements
Chapter Outline
Learning Outcomes
5.1 Introduction
5.2 The while Loop
5.2.1 Details of while Loop
5.2.2 Flowchart for while Loop
5.2.3 Some More Programs on while Loop
5.3 The range() Function
5.3.1 Examples of range() Function
5.4 The for Loop
5.4.1 Details of for Loop
5.4.2 Some More Programs on for Loop
5.5 Nested Loops
5.5.1 Some More Programs on Nested Loops
5.6 The break Statement
5.7 The continue Statement
Mini Project Generate Prime Numbers Using Charles Babbage Function
Summary
Key Terms
Review Questions
Programming Assignments
6. Functions
Chapter Outline
Learning Outcomes
6.1 Introduction
6.2 Syntax and Basics of a Function
6.3 Use of a Function
6.4 Parameters and Arguments in a Function
6.4.1 Positional Arguments
6.4.2 Keyword Arguments
6.4.3 Parameter with Default Values
6.5 the Local and Global Scope of a Variable
6.5.1 Reading Global Variables from a Local Scope
6.5.2 Local and Global Variables with the Same Name
6.5.3 The Global Statement
6.6 The return Statement
6.6.1 Returning Multiple Values
6.6.2 Assign Returned Multiple Values to Variable(s)
6.7 Recursive Functions
6.8 The Lambda Function
Mini Project Calculation of Compound Interest and Yearly Analysis of Interest and Principal Amount
Summary
Key Terms
Review Questions
Programming Assignments
7. Strings
Chapter Outline
Learning Outcomes
7.1 Introduction
7.2 The str Class
7.3 Basic Inbuilt Python Functions for String
7.4 The index[] Operator
7.4.1 Accessing Characters via Negative Index
7.5 Traversing String with for and while Loop
7.5.1 Traversing with a while Loop
7.6 Immutable Strings
7.7 The String Operators
7.7.1 The String Slicing Operator [start: end]
7.7.2 String Slicing with Step Size
7.7.3 The String +, * and in Operators
7.8 String Operations
7.8.1 String Comparison
7.8.2 The String .format() Method()
7.8.3 The split() Method
7.8.4 Testing String
7.8.5 Searching Substring in a String
7.8.6 Methods to Convert a String into Another String
7.8.7 Stripping Unwanted Characters from a String
7.8.8 Formatting String
7.8.9 Some Programs on String
Mini Project Conversion of Hexdecimal Number into Its Equivalent Binary Number
Summary
Key Terms
Review Questions
Programming Assignments
8. Lists
Chapter Outline
Learning Outcomes
8.1 Introduction
8.2 Creating Lists
8.3 Accessing the Elements of a List
8.4 Negative List Indices
8.5 List Slicing [start: end]
8.6 List Slicing with Step Size
8.6.1 Some More Complex Examples of List Slicing
8.7 Python Inbuilt Functions for Lists
8.8 The List Operator
8.9 List Comprehensions
8.9.1 Some More Examples of List Comprehension
8.10 List Methods
8.11 List and Strings
8.12 Splitting a String in List
8.13 Passing List to a Function
8.14 Returning List from a Function
Summary
Key Terms
Review Questions
Programming Assignments
9. List Processing: Searching and Sorting
Chapter Outline
Learning Outcomes
9.1 Introduction
9.2 Searching Techniques
9.2.1 Linear/Sequential Search
9.2.2 The Binary Search
9.3 Introduction to Sorting
9.3.1 Types of Sorting
9.3.2 Bubble Sort
9.3.3 Selection Sort
9.3.4 Insertion Sort
9.3.5 Quick Sort
9.3.6 Merge Sort
Mini Project Sorting Based on the Length of Each Element
Summary
Key Terms
Review Questions
Programming Assignments
10. Object-Oriented Programming: Class, Objects and Inheritance
Chapter Outline
Learning Outcomes
10.1 Introduction
10.2 Defining Classes
10.2.1 Adding Attributes to a Class
10.2.2 Accessing Attributes of a Class
10.2.3 Assigning Value to an Attribute
10.3 the Self-parameter and Adding Methods to a Class
10.3.1 Adding Methods to a Class
10.3.2 the Self-parameter
10.3.3 Defi Ning Self-parameter and Other Parameters in a Class Method
10.3.4 the Self-parameter with Instance Variable
10.3.5 the Self-parameter with Method
10.4 Display Class Attributes and Methods
10.5 Special Class Attributes
10.6 Accessibility
10.7 The init Method (Constructor)
10.7.1 Attributes and init Method
10.7.2 More Programs on init Method
10.8 Passing an Object as Parameter to a Method
10.9 del() (Destructor Method)
10.10 Class Membership Tests
10.11 Method Overloading in Python
10.12 Operator Overloading
10.12.1 Special Methods
10.12.2 Special Methods for Arithmetic Operations
10.12.3 Special Methods for Comparing Types
10.12.4 Reference Equality and Object Equality
10.12.5 Special Methods for Overloading Inbuilt Functions
10.13 Inheritance
10.14 Types of Inheritance
10.15 The Object Class
10.16 Inheritance in Detail
10.17 Subclass Accessing Attributes of Parent Class
10.18 Multilevel Inheritance in Detail
10.19 Multiple Inheritance in Detail
10.19.1 More Practical Examples on Inheritance
10.20 Using super()
10.20.1 Super to Call Super Class Constructor
10.21 Method Overriding
10.22 Precaution: Overriding Methods in Multiple Inheritance
Mini Project Arithmetic Operations on Complex Numbers
Summary
Key Terms
Review Questions
Programming Assignments
11. Tuples, Sets and Dictionaries
Chapter Outline
Learning Outcomes
11.1 Introduction
11.1.1 Creating Tuples
11.1.2 The tuple()function
11.1.3 Inbuilt Functions for Tuples
11.1.4 Indexing and Slicing
11.1.5 Operations on Tuples
11.1.6 Passing Variable Length Arguments to Tuples
11.1.7 Lists and Tuples
11.1.8 Sort Tuples
11.1.9 Traverse Tuples from a List
11.1.10 The zip() Function
11.1.11 The Inverse zip() Function
11.1.12 More Examples on zip() Function
11.1.13 More Programs on Tuples
11.2 Sets
11.2.1 Creating Sets
11.2.2 The Set in and not in Operator
11.2.3 The Python Set Class
11.2.4 Set Operations
11.3 Dictionaries
11.3.1 Need of Dictionaries
11.3.2 Basics of Dictionaries
11.3.3 Creating a Dictionary
11.3.4 Adding and Replacing Values
11.3.5 Retrieving Values
11.3.6 Formatting Dictionaries
11.3.7 Deleting Items
11.3.8 Comparing Two Dictionaries
11.3.9 The Methods of Dictionary Class
11.3.10 Traversing Dictionaries
11.3.11 Nested Dictionaries
11.3.12 Traversing Nested Dictionaries
11.3.13 Simple Programs on Dictionary
11.3.14 Polynomials as Dictionaries
Mini Project Orange Cap Calculator
Summary
Key Terms
Review Questions
Programming Assignments
12. Graphics Programming: Drawing with Turtle Graphics
Chapter Outline
Learning Outcomes
12.1 Introduction
12.2 Getting Started with the Turtle Module
12.3 Moving the Turtle in any Direction
12.3.1 Programs to Draw Different Shapes
12.4 Moving Turtle to Any Location
12.5 The color, bgcolor, circle and Speed Method of Turtle
12.6 Drawing with Colors
12.7 Drawing Basic Shapes Using Iterations
12.8 Changing Color Dynamically Using List
12.9 Turtles to Create Bar Charts
Mini Project Turtle Racing Game
Summary
Key Terms
Review Questions
Programming Assignments
13. File Handling
Chapter Outline
Learning Outcomes
13.1 Introduction
13.2 Need of File Handling
13.3 Text Input and Output
13.3.1 Opening a File
13.3.2 Writing Text to a File
13.3.3 Closing a File
13.3.4 Writing Numbers to a File
13.3.5 Reading Text from a File
13.3.6 Reading Numbers from a File
13.3.7 Reading Multiple Items on one Line
13.3.8 Appending Data
13.4 The seek() Function
13.5 Binary Files
13.5.1 Reading Binary Files
13.6 Accessing and Manipulating Files and Directories on a Disk
Mini Project Extracting Data from a File and Performing Some Basic Mathematical Operations on It
Summary
Key Terms
Review Questions
Programming Assignments
Appendix I: Project for Creating a Phone Book Directory
Appendix Ii: Importing Modules in Python
Appendix Iii: Python Keywords
Appendix Iv: Ascii Table
Index
π SIMILAR VOLUMES
This book offers a step-by-step approach to the fundamentals and the theoretical concepts of Python programming. Each program is followed by its detailed explanation, which will help students in understanding the concepts. It aims to facilitate practical understanding with numerous programs and solv
Python is a robust, procedural, object-oriented, and functional language. The features of the language make it valuable for web development, game development, business, and scientific programming. This book deals with problem-solving and programming in Python. It concentrates on the development of e
<span>Python is a robust, procedural, object-oriented, and functional language. The features of the language make it valuable for web development, game development, business, and scientific programming. This book deals with problem-solving and programming in Python. It concentrates on the developmen