- Home
- Lessons
- KS3 Computing
- Modelling the real world
Modelling the real world
🎬 The doodle video for this lesson is coming soon. Subscribe on YouTube to see it first.
Weather forecasts, games and traffic systems all use computer models. A model is an abstraction: it keeps only the parts of the real world that matter.
State and behaviour
A model needs to store the state of the system: the data that describes it right now, such as the current light colour or the temperature.
It also needs behaviour: the rules for how the state changes.
In a program, variables and lists hold the state; selection and loops carry out the rules.
It also needs behaviour: the rules for how the state changes.
In a program, variables and lists hold the state; selection and loops carry out the rules.
Example: UK traffic lights
UK traffic lights go: red, red and amber, green, amber, then back to red.
states = ["red", "red and amber", "green", "amber"]
now = 2
now = (now + 1) % 4
print(states[now])
now = 2 means green. Adding 1 and using % 4 (remainder) moves on, wrapping back to 0 after 3.
Output: amber
states = ["red", "red and amber", "green", "amber"]
now = 2
now = (now + 1) % 4
print(states[now])
now = 2 means green. Adding 1 and using % 4 (remainder) moves on, wrapping back to 0 after 3.
Output: amber
Example: a heating system
target = 20
temp = 18
if temp < target:
heating = "on"
else:
heating = "off"
print(heating)
Output: on
The state is the temperature and target; the rule is: heat if colder than the target.
Evaluate a model by comparing it with real life. Did it leave out something important, such as an open window?
temp = 18
if temp < target:
heating = "on"
else:
heating = "off"
print(heating)
Output: on
The state is the temperature and target; the rule is: heat if colder than the target.
Evaluate a model by comparing it with real life. Did it leave out something important, such as an open window?
In the traffic light model, what is shown after amber (now = 3)?
- now = (3 + 1) % 4 = 0.
- states[0] is red.
Answer: red
A model is an abstraction of a real system. State is the data describing it now; behaviour is the rules for how it changes. Evaluate a model by checking it against reality.
Check you have got it
Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.