
for Beginners
ISBN: | 978-9-814-74296-2 |
---|---|
Publisher: | McGraw Hill Education |
Year: | 2016 |
Pages: | 248 |
Overview of the Book
This book is designed to help you understand the Python programming language and learn how to write elementary programs in Python. The content is suitable for anyone who does not have previous programming experience. After you have completed this book, you should have a strong understanding of the fundamentals of the Python programming language so that you will feel confident in exploring more advanced techniques and programming concepts later on.
This book contains more than 70 code examples to help explain the concepts and techniques in each chapter. All of these examples can be downloaded from here. There are also over 90 exercises at the end of the chapters. Some of these exercises consolidate your knowledge in each chapter and some of them are bigger programming exercises for you to practise your programming skill.
- Chapter 1 Introduction to Python
- 1.1 Getting Started with Python
- Welcome to Interactive Python Programming for Beginners!
- The Python Programming Language
- Python Programs
- Using Python
- 1.2 Using IDLE
- Running IDLE
- Using the Shell Window
- Using the Editor Window
- 1.1 Getting Started with Python
- Chapter 2 Basic Turtle Graphics Programming
- 2.1 Introduction to Turtle Graphics
- What is Turtle Graphics?
- How to Draw Things Using the Turtle
- 2.2 Getting Started with Turtle Graphics
- Using Turtle Graphics in Python
- Working with the Turtle Window
- Understanding the Turtle
- 2.3 Moving the Turtle
- Moving Forward and Backward
- Turning the Turtle
- Moving to a Specific Location
- Moving Around a Circle
- Adjusting the Speed of the Turtle
- 2.4 Using the Pen
- Lifting the Pen Up and Putting the Pen Down
- Changing the Thickness and Colour of the Line
- Filling Shapes
- 2.5 Other Useful Commands
- Showing and Hiding the Turtle
- Drawing Dots
- Writing Text
- Clearing the Turtle Window
- Exercises
- 2.1 Introduction to Turtle Graphics
- Chapter 3 Comments, Variables and Text
- 3.1 Writing Comments in Code
- Writing Simple Comments
- Writing Multiple Lines of Comments
- Hiding Code Temporarily Using Comments
- 3.2 Variables
- Creating and Assessing Variables
- Variable Names
- 3.3 Text Input and Output
- Understanding Strings
- Showing Text Output
- Getting Text Input
- Exercises
- 3.1 Writing Comments in Code
- Chapter 4 Variable Types and Operators
- 4.1 Variable Types
- Basic Data Types in Python
- Converting Between Data Types
- 4.2 Basic Operators
- Arithmetic Operators
- String Operators
- Using a Shortcut with the Equals Sign
- Operator Precedence
- Exercises
- 4.1 Variable Types
- Chapter 5 Making Decisions
- 5.1 Making Decisions Using If Statements
- The If Statements
- Indentation in Python
- The Else Statements
- 5.2 Building Conditions Using Operators
- Comparing Things Using Comparison Operators
- Working with Boolean Values Using Logical Operators
- 5.3 Nested If Statements
- Building a Program Using Nested If Statements
- Using Elif Statements
- Exercises
- 5.1 Making Decisions Using If Statements
- Chapter 6 Looping
- 6.1 Repeating Things by Looping
- 6.2 While Loops
- Loops That Never End
- Nested While Loops
- 6.3 For Loops
- The Range Command
- Creating a For Loop Using the Range Command
- Nested For Loops
- 6.4 Stopping Loops
- The Continue Command
- The Break Command
- Exercises
- Chapter 7 Finding Repeating Patterns
- 7.1 The % Operator
- Determining Odd or Even Numbers
- 7.2 Using the % Operator for Repeating Patterns
- Odd and Even Numbers as a Pattern
- Getting Patterns with a Different Size
- Making a Chess Board
- Exercises
- 7.1 The % Operator
- Chapter 8 Lists, Tuples and Strings
- 8.1 Managing a Collection of Things
- Lists
- Tuples
- Strings
- 8.2 Using a Collection with a For Loop
- Using a List with a For Loop
- Using a String with a For Loop
- 8.3 Slicing
- Default Values for Slicing
- Using Negative Item Indices
- 8.4 Operators for Lists, Tuples and Strings
- The Addition and Multiplication Operators
- The Membership Operators
- Finding the Size of a Collection
- 8.5 Making a List of Lists
- Exercises
- 8.1 Managing a Collection of Things
- Chapter 9 Functions
- 9.1 Repeating Things in Different Places
- Using Functions
- 9.2 Making and Using a Function
- Making a Function
- Using a Function
- 9.3 Passing Values into a Function
- Making a Function with an Input Variable
- Using a Function with an Input Variable
- Using Multiple Input Variables
- 9.4 Returning Values from a Function
- Stopping a Function Using the Return Command
- Returning Values Using the Return Command
- 9.5 Local and Global Variables
- Local Variables
- Global Variables
- Changing Local Variables
- Changing Global Variables inside a Function
- Exercises
- 9.1 Repeating Things in Different Places
- Chapter 10 Dictionaries
- 10.1 A Dictionary is a Mapping
- 10.2 Using Dictionaries
- Creating a Dictionary
- Getting a Value from a Dictionary
- Modifying a Dictionary
- 10.3 Going Through a Dictionary
- Getting the Keys of a Dictionary
- Getting the Values of a Dictionary
- Going Through the Items
- 10.4 Using the Membership Operators
- Exercises
- Chapter 11 More on Turtle
- 11.1 Controlling the Turtle Animation
- Changing the Turtle Speed
- Turning On or Off the Animation
- 11.2 Changing the Turtle Shape
- Using Other Turtle Shapes
- Changing the Size of the Turtle Shape
- Changing the Outline of the Turtle Shape
- 11.3 Getting Information about the Turtle
- The Position and Heading of the Turtle
- Other Properties of the Turtle
- 11.4 Making More Turtles
- Exercises
- 11.1 Controlling the Turtle Animation
- Chapter 12 Turtle Window Event Handling
- 12.1 Graphical User Interfaces and Event Handling
- The Turtle Window as a Graphical User Interface
- Handling GUI Events
- 12.2 Turtle Window Events
- Two Categories of Turtle Window Events
- 12.3 Handling Turtle Events
- Using the Turtle Click Event
- Using the Turtle Drag Event
- Using Turtle Events for Multiple Turtles
- 12.4 Handling Turtle Screen Events
- The Turtle Screen Click Event
- The Turtle Key Press Event
- The Turtle Timer Event
- Exercises
- 12.1 Graphical User Interfaces and Event Handling
- Chapter 13 File Handling
- 13.1 Using Text Files
- Opening a Text File
- Closing a Text File
- Saving and Loading Data for a Turtle Program
- 13.2 Saving Data to a Text File
- Using the Write Command
- Extending the Turtle Program
- 13.3 Loading Data from a Text File
- Reading Content Using a Loop
- Extending the Turtle Program
- Exercises
- 13.1 Using Text Files
- Chapter 14 Programming with Objects
- 14.1 Introduction to Objects
- Attributes and Behaviours
- Object Oriented Programming
- 14.2 Making a Class
- Making the Attributes
- Making the Methods
- 14.3 Using a Class
- Creating an Object from the Class
- Creating Multiple Objects
- Exercises
- 14.1 Introduction to Objects
- Chapter 15 Recursion
- 15.1 What is Recursion?
- Recursion in Programming
- 15.2 Writing a Recursive Function
- Running the Recursive Function
- Setting up the Base Case
- The Recursive Depth
- 15.3 Using Recursion in Computer Graphics
- The Sierpinski Triangle
- Drawing a Recursive Tree
- Exercises
- 15.1 What is Recursion?
Where to Find the Book
You can find the book in the HKUST bookstore.