Year 9 Revision Guide
9.1 Introduction to Python
Lesson 1 – Introduction Rules for variables
• A variable name can contain only numbers, letters and underscores
• A variable name cannot start with a number
• You can’t use a Python “reserved word” as a variable name – for example
class is a reserved word so class = input() will result in a syntax error.
Python’s Development Environment
IDLE – Integrated Development Environment. There are two Modes:
– Interactive Mode let you see your results as you type them
– Script Mode lets you save your program and run it again later
Variables
• A variable is a location in memory in which you can temporarily store text
or numbers
• It is used like an empty box or the Memory function on a calculator
• You can choose a name for the box (the “variable name”) and change its
contents in your program
Lesson 2 – Numbers and arithmetic
Data types
• String holds alphanumeric data as text
• Integer holds whole numbers
• Float holds numbers with a decimal point
• Boolean holds either ‘True’ or ‘False’
Defining variable data types
• Python automatically assigns a data type to a variable
• You can override this to manually define or change the data type using:
– str() str(animal_name)
– int() int(goals_scored)
– float() float(share_price)
• This is called Casting
Lesson 3 – Selection
Lesson 4 – Writing algorithms Types of programming error
Writing pseudocode Syntax Errors - when a line of code cannot be understood – eg missing a “ or )
• Pseudocode is half code, half English [Link]
• It has no real syntax and would not run
Run-Time Errors – a run-time error is caused by a problem that the program cannot
• It is a structured sequence of instructions resolve whilst it is running. An example would be a division by zero, or being unable
to locate a file that the program is looking for.
• It is useful for planning algorithms
[Link]
Suggested language for pseudocode
• Use indentation in pseudocode Logic errors - a program with a logic error will run and appear to be working.
However a calculation may be wrong and cause a wrong result to be output.
• Use words such as: Program may crash.
[Link]
print, display,
input, output,
calculate, add,
set, reset,
if, then, else
Lesson 5 – While loops
Lesson 6 – Convergence and new technologies