Learning to Program
Essential skills to code in Python for KS3 & KS4
Saagar Jagatia
Release Information and Copyright Notice
© This material is subject to copyright. You are free to use this for your own personal use and for other teachers within your institution, including photocopies to those. You may not copy, photo-copy or e-mail this document to parties outside your institution. The University of Worcester logo and related trademarks may not be used without permission directly from the University.
The information contained in this resource pack are from sources believed to be reliable. However, because of the possibility of human or mechanical error by our sources I cannot guarantee the accuracy, adequacy or completeness of any information. Readers should also be particularly aware of the fact that the internet is an ever-changing entity. Some facts may change once this book is released.
The software used throughout this pack may be upgraded by the developers, which may alter your experience of the language and the software packages.
Release: SHJagatia;
06th November 2012, Draft 1.11th December 2012, Draft 2. 16th January 2013, Draft 3.28th February 2013, Final Draft.
Table of Contents
Learning to Program 1
Release Information and Copyright Notice 2
Table of Contents 3
Forward 6
Preface 7
My Project Mission 9
Acknowledgements 9
Intro 1a. How To Use This Book 10
Working through the sections 10
Code Examples 10
Intro 1b. Programming in School 11
Logo 11
Scratch 13
Intro 2. Learning and Teaching how to Program 14
Modification (Modding) 14
Extension 14
Collage 14
Reading Code 15
Coding from Scratch 15
Intro 3a. Introduction to Software Development 16
Iterative Development 16
Professional Iterative Software Development 16
Debugging 16
Intro 3b. Strategies for Debugging in Python 17
Syntax Errors 17
Debugging Example 18
Intro 4. Introduction To The Python Language 19
Downloading, Installing, Configuring and Running Python 19
Let’s begin. 22
Official Python Cheat Sheet – for a real head start with the language 23
Now some Python Basics 24
TECHNICAL STUFF: 25
Some Rules and Information 27
Naming Rules 27
Python Data Types 27
Modules 28
Comparing Strings 29
TECHNICAL STUFF: 29
The Three Ds 29
Lesson 1. Lets Dive Into The Code 30
Example 1: Numerical Input.py 30
Example 2: GuessTheNumberBySaagarJagatia.py 32
Example 3: HangmanBySaagarJagatia.py 33
Lesson 2. Understanding the Python Library: ‘Import’ & Creating Modules 39
Using & importing Modules 39
Creating Modules 40
Lesson 3. Understanding a Created Library 41
Graphical Outputs 41
Lesson 4. Tkinter an Introduction 43
Here is a Complete Example 44
Features of Tkinter 44
Example 1: Helloworld.py 45
Example 2: SimpleCalculator.py 46
Tkinter in school: 47
Tkinter Widgets Table 48
Font Style Options 48
Tk Option Data Types 49
Lesson 5. PyProcessing an Introduction 51
Example 1: PyProcessing 54
Example 2: Helloworld.py 55
Example 3: Helloworldrot.py 56
PyProcessing Questions and Challenges 57
Pyprocessing in school: 58
Pyprocessing Variables 59
Structure 59
Image 59
Environment 60
Colour 61
Shape 62
Input 63
Math 65
Transform 65
Lights, Camera 66
Camera 67
Pyglet Package – Extension task 68
Lesson 5: Python Challenges Questions 71
Python Challenges Answers 72
Appendix – Code Snippets 76
Debugging 76
Python Basics - Maths 76
Python - Example 1: Numerical Input.py 76
Example 2: GuessTheNumberBySaagarJagatia.py 77
Example 3: HangmanBySaagarJagatia.py 78
Tkinter - Example 1:HelloWorld.py 82
Example 2: SimpleCalculator.py 83
PyProcessing - Example 1:PyProcessing.py 84
Example 2:HelloWorld.py 85
Example 3: HelloWorldRot.py 85
Something fun for class 86
1 player pong 86
References 89
Forward
This resource pack was written as part of an independent study during a third year degree course at, the University of Worcester. This resource pack contains information to assist the drive towards concepts and skills allied to Computer Science, and its introduction into the secondary school curriculum at KS4 (GSCE) level.
This book will focus on the Python programming language. Following a meeting with the regional organiser of CAS (Computing at Schools) group and Dr, Colin B Price of University of Worcester, there was a mutual feeling that Python is a useful language to introduce to KS4 level pupils to prepare them for further Computing Studies beyond school, (KS5). In order to test this theory, this book will aid the research to see how KS4 pupils respond to the Python language, and whether or not it is an appropriate programming language at the KS3/KS4 level.
This piece of work is aimed at teachers and maybe their pupils. It will guide teachers on how to use Python within their classes.
...
maniac64