Welcome

Python Programming provides a comprehensive introduction to the problem-solving and programming skills that you will need for GCSE.

There are 15 topic areas, each with explanations, examples and annotated code-snippets - plus a range of exercises for you to practise.

As you develop your knowledge of Python, the range of tasks set become more challenging and demonstrate possible methods of approaching programming project-style tasks, with an emphasis on how to make the code both efficient and robust at every opportunity.

In addition, there five stand-alone practical programming problems designed to challenge all ability levels, as well as 24 starter activities.

Key Conventions

Version of Python

The version of Python that is used in all examples in this resource is version 3.7.2.

Python Modes

Python has two modes: interactive and script.

IDE (Integrated Development Environment

The IDE shown in some screenshots in the resource is JetBrains PyCharm Community Edition. There are many different IDEs available; this one has all the debugging features that GCSE students will need while not being too complex to understand.

Python and SQL

In topic (14) Databases, the method of connecting to a simple database application uses sqlite3, which is imported as a module into Python 3. The SQLite browser is also used to allow students a visual method of interacting with a simple database. This open source software can be downloaded here: https://sqlitebrowser.org/

Efficient & Robust Code

The ability to write efficient and robust code is an important part of learning to write effective programs.
Specific examples of efficient and robust code are identified wherever these two icons appear on the page:

Writing Readable Code: PEP 8 Guidelines

Readability involves the use of consistent styles and layout to make your code easy for you and others to read and understand.

Variable and function names

The key points to follow are the consistent use of lower case and underscores to make variable and function names easier to read and make the purpose of the variable clearer.

Example 1:

Following PEP 8 guidelines:

The exception to this rule is the naming of variables which are constants, i.e. where the value remains unchanged when the program is executed.

Example 2:

Constant names should be all upper case, separating words using an underscore where relevant. The number of points for winning, losing or drawing a football game does not change so these are shown as constant values.

Use of whitespace in expressions and statements

The key points to follow here are ensuring that there is a space either side of an operator. Make sure that the space bar is used, NOT the TAB key as this will result in an error when the code is executed.

The use of whitespace by leaving a line space between Python statements can also improve the readability of the code, as will leaving two lines space between each function in longer sections of code.

Example:

Following PEP 8 guidelines:

The function names used in the first example were also too close to the variable names used, so these were amended as well.

Looking at the two improved versions, it is obvious that the second version is clearer and easier to read.

Using these guidelines will help you and your teacher understand what your code means when you return to it each lesson.