Loading...
A variable names a stored value that can change; a constant represents a value intended to remain fixed. Common types include integer, real, Boolean and string. Python input returns text, so numeric work often requires a conversion. The + operator can add numbers or concatenate strings depending on types. Use clear names and keep assignment distinct from equality comparison. The expression x == 3 tests a condition, while x = 3 assigns.
Video by Craig'n'Dave. The video’s own board label is retained; follow the specification reference and scope notes on this lesson for assessed content.
Viewing focus: Use variables, types and casting
After watching, attempt these questions before opening the answers. You can also use the written lesson below.
After watching 1: What does Python range(2,5) produce?
2, 3, 4. The stop value is excluded.
After watching 2: Which type represents true or false?
Boolean. Conditions evaluate to Boolean values.
What you'll be able to do
A variable names a stored value that can change; a constant represents a value intended to remain fixed. Common types include integer, real, Boolean and string. Python input returns text, so numeric work often requires a conversion. The + operator can add numbers or concatenate strings depending on types. Use clear names and keep assignment distinct from equality comparison. The expression x == 3 tests a condition, while x = 3 assigns.
Sequence executes statements in order. Selection chooses a branch according to a condition. Iteration repeats work using a counted or condition-controlled loop. In Python, indentation defines blocks and range(1,4) produces 1, 2 and 3, excluding the endpoint. A while loop needs its condition to become false for normal termination; forgetting an update can cause an unintended infinite loop.
Combine arithmetic, comparison and Boolean operators carefully and use brackets when they improve clarity. A condition for a valid age range should include the intended endpoints. Test normal, boundary and invalid cases rather than only a value that follows the easiest path. Printing an intermediate variable can help debugging, but the final program should meet the required output format. A program can run successfully and still implement the wrong rule.
total = 0
for number in range(1, 4):
total += number
print(total)Scroll horizontally to see the full code or table.Attempt these problems on paper before opening the worked reasoning. Explain your steps as well as giving a final answer.
Common mistakes to avoid
Key takeaways
Question 1: Write a condition for an integer score from 0 to 100 inclusive.
0 <= score <= 100 in Python.
Check the assessed scope and practical or mathematical requirements.
An external explanation or interactive activity to use alongside the lesson. It may include extension material.
Close the notes and answer from memory. Revisit any explanation you cannot yet reconstruct.
Test yourself
Answer a few questions, then review anything you missed.
Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.