Skip to content

Programming (blocks and Python)

KS3 Computing revision notes, key terms and practice questions.

In short

A variable is a named store for data that can change: score = 0. A constant is a value that doesn't change. Data types: integer (a whole number, such as 7), float or real (a decimal, such as 2.5), string (text, in quotes, such as "Sam") and Boolean (True or False).

For KS3 students in Years 7, 8 and 9 (KS3 Computing).

Variables and data types

  • A variable is a named store for data that can change: score = 0. A constant is a value that doesn't change.
  • Data types: integer (a whole number, such as 7), float or real (a decimal, such as 2.5), string (text, in quotes, such as "Sam") and Boolean (True or False).
  • Input and output in Python: name = input("What is your name? ") and print("Hello", name).
  • input() always gives a string, so use int() to turn it into a whole number: age = int(input("How old are you? ")).

Selection and iteration

  • Selection: if score >= 50: … elif … else: … In Python, indentation shows which lines belong inside the if statement.
  • A FOR loop repeats a set number of times: for i in range(5): repeats 5 times, with i going from 0 to 4.
  • A WHILE loop repeats while a condition is true, for example until the user guesses the right answer.
  • Block-based languages such as Scratch use the same ideas, with blocks instead of typed code.

Operators and lists

  • Arithmetic: + − * /, // (whole-number division), % (remainder) and ** (power). 17 // 5 is 3 and 17 % 5 is 2.
  • Comparison: == (equal to), != (not equal to), <, >, <= and >=. Logic: and, or, not.
  • A list stores several items: fruits = ["apple", "pear"]. Positions (indexes) start at 0, so fruits[0] is "apple".

Errors and testing

  • A syntax error breaks the rules of the language, such as a missing bracket, so the program won't run.
  • A logic error lets the program run, but it gives the wrong result.
  • Test with normal data (typical values), boundary data (at the edge of what is allowed) and invalid data (values that should be rejected).

Key terms

Variable
A named store for data that can change.
Constant
A value that doesn't change while a program runs.
Integer
A whole number.
Float
A number with a decimal point (also called real).
String
Text, written inside quotation marks.
Boolean
A value that is either True or False.
FOR loop
A loop that repeats a set number of times.
WHILE loop
A loop that repeats while a condition is true.
List
A data structure that stores several items in order.
Index
The position of an item in a list, starting at 0.
Syntax error
A mistake that breaks the rules of the programming language.
Logic error
A mistake that makes a program give the wrong result.

Quick questions on Programming (blocks and Python)

What is a variable?
A named store for data that can change: For example, score = 0.
Which data type stores text?
String: Strings go inside quotation marks.
Which data type can only be True or False?
Boolean: It is named after the mathematician George Boole.
What does print() do in Python?
Displays output on the screen: input() asks the user a question.
Why is int() used with input() in Python?
input() gives text, and int() turns it into a whole number: You can't do maths with text.
How many times does for i in range(5): repeat?
5 times: i goes 0, 1, 2, 3, 4.
What does == mean in Python?
Is equal to (comparing two values): A single = stores a value in a variable.
What does != mean in Python?
Not equal to: For example: while guess != answer:

Programming (blocks and Python): questions and answers

What is the index of the first item in a Python list?
Indexes start at 0.
What is a syntax error?
A mistake that breaks the rules of the language, such as a missing bracket. The program won't run until it is fixed.
What is a logic error?
The program runs but gives the wrong result. Testing helps find logic errors.

Practise Programming (blocks and Python): 15 questions

Download these notes as a PDF

Previous topic: AlgorithmsNext topic: Binary and data

More in Computer science

LycoLearn is still loading…

This can take a little longer on a busy school or home network. If nothing happens, try refreshing the page.

LycoLearn didn’t load properly

Part of it didn’t arrive. Try refreshing the page in a minute, or open LycoLearn in another browser.