Python Computer Science
Beginner
120 mins
Teacher/Student led
What you need:
Chromebook/Laptop/PC

Modelling in Design

In this lesson, you'll explore the core ideas of simplifying and solving real-world problems through programming. You'll gain practical experience by creating Python programs that apply abstraction, modelling, and simulation concepts to tackle design challenges effectively.
Learning Goals Learning Outcomes Teacher Notes

Teacher Class Feed

Load previous activity

    1 - Introduction

    In this lesson on Modelling in Design, you'll dive into key concepts that help simplify and solve real-world problems using programming. By the end, you'll have hands-on experience building Python programs that apply these ideas.

    Here's what you'll be learning and doing:

    1. Explore abstraction: Understand how to focus on essential features while ignoring unnecessary details to make complex systems manageable.
    2. Learn about modelling: Discover how to create simplified representations of real-world systems for analysis and prediction.
    3. Understand simulation: See how to run models over time to imitate behaviours and test scenarios.
    4. Complete practical tasks: Write Python code to practice abstraction, modelling, and simulation in separate programs.
    5. Build your own project: Combine these concepts into a small Python project, like simulating a virtual garden or a basic stock market.

    2 - Understanding Abstraction

    Abstraction is a key concept in computer science and design. It means simplifying complex systems by focusing on the essential features while ignoring unnecessary details. This helps in problem-solving by making problems more manageable.

    For example, when modelling a car's movement, you might abstract away details like the colour or brand and focus on speed, distance, and time. This creates an abstract model that represents the real-world system in a simplified way.

    Abstraction is used in software design to create models that can be simulated and tested. It allows you to solve problems by breaking them down into core components.

    Think of abstraction like a map: it shows roads and landmarks but ignores small details like individual trees, yet it's useful for navigation.

    3 - Task: Abstraction

    Abstraction in programming means simplifying complex things by hiding unnecessary details and focusing on what's important. For example, you don't need to know how a car's engine works to drive itβ€”you just use the steering wheel and pedals.

    Your Task: Create a simple Python program that abstracts a "Pet" object. We'll use a class to hide the details of how the pet's hunger or happiness changes, and just provide easy methods to interact with it.

    Create a new folder in VS Code called ModellingLesson and a file named pet_abstraction.py inside it.

    Add the following complete code to pet_abstraction.py:

    class Pet:
        def __init__(self, name):
            self.name = name
            self.hunger = 50  # Hidden detail: starts at 50/100
            self.happiness = 50  # Hidden detail: starts at 50/100
    
        def feed(self):
            self.hunger -= 10  # Abstracted: just feed, don't worry about how
            if self.hunger < 0:
                self.hunger = 0
            print(f"{self.name} has been fed! Hunger is now {self.hunger}.")
    
        def play(self):
            self.happiness += 10  # Abstracted: just play, happiness increases
            if self.happiness > 100:
                self.happiness = 100
            print(f"{self.name} is playing! Happiness is now {self.happiness}.")
    
        def status(self):
            print(f"{self.name}'s status: Hunger = {self.hunger}, Happiness = {self.happiness}")

    Now, add code at the bottom to create a pet and test it:

    my_pet = Pet("Buddy")
    my_pet.feed()
    my_pet.play()
    my_pet.status()

    Run the program (press F5 or use the terminal with python pet_abstraction.py).

    How does the class abstract the details? You don't need to manually change hunger or happinessβ€”the methods handle it for you. Try modifying the class to add another abstracted method, like sleep() that reduces hunger but increases happiness.
    This task shows abstraction by letting you interact with the pet without dealing with the internal math.

    4 - Understanding Modelling

    Modelling is the process of creating a simplified representation of a real-world system or problem to understand, analyse, or predict its behaviour. It builds directly on abstraction by taking those essential features and using them to build models that can be tested and refined.

    In the context of design and software engineering, modelling allows us to break down complex problems into manageable parts. Models can be mathematical equations, diagrams, or computer simulations that mimic how a system works. This helps in problem-solving by enabling us to experiment with different scenarios without dealing with the full complexity of the real world.

    For example, if you're designing a new app for traffic management, you might create a model that simulates car movements based on speed, road capacity, and traffic lights, ignoring minor details like weather unless they're crucial.

    Modelling is essential in the software development process because it helps identify potential issues early, evaluate solutions, and optimise designs before implementation.

    Think of modelling like creating a blueprint for a building: it represents the structure and functions without actually constructing it, allowing you to spot problems and make improvements beforehand.

    5 - Task: Modelling

    Modelling means creating a digital representation of something real-world, like a map models a city or a budget models your spending.

    Your Task: Model a simple "Weather Forecast" system. We'll use variables and a function to represent daily weather data, like temperature and rain chance.

    Create a new file named weather_model.py and add the following complete code to it:

    def weather_model(day, temperature, rain_chance):
        # This function models the weather for a given day
        if rain_chance > 50:
            forecast = "Rainy"
        elif temperature > 25:
            forecast = "Sunny and warm"
        else:
            forecast = "Cloudy and cool"
        
        print(f"Day: {day}")
        print(f"Temperature: {temperature}Β°C")
        print(f"Rain Chance: {rain_chance}%")
        print(f"Forecast: {forecast}")
        print("-------------------")
    
    # Example data to model a week's weather
    weather_model("Monday", 22, 30)
    weather_model("Tuesday", 28, 60)
    weather_model("Wednesday", 15, 80)

    Run the program and you should see that it outputs the weather details and forecasts for Monday as 'Cloudy and cool', Tuesday as 'Rainy', and Wednesday as 'Rainy'.

    Extension: Add more days or change the model. For example, add a condition for "Snowy" if temperature < 0. What happens if you input extreme values like temperature = 50 or rain_chance = 100?
    This models real weather by simplifying it into key parts (temperature, rain).

    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    Copyright Notice
    This lesson is copyright of DigitalSkills.org 2017 - 2025. Unauthorised use, copying or distribution is not allowed.
    πŸͺ Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more