Python Computer Science
Beginner
80 mins
Teacher/Student led
+115 XP
What you need:
Chromebook/Laptop/PC

Computational Thinking & Real-World Examples

In this lesson, you will learn about computational thinking concepts like decomposition and pattern recognition. You will also explore how these skills are applied in real-world computer science scenarios. Through hands-on exercises and coding tasks, you will practise breaking problems into smaller parts and identifying patterns to solve them efficiently.
Learning Goals Learning Outcomes Teacher Notes

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Introduction to Computational Thinking

    Computational thinking involves breaking down problems into smaller, manageable parts (decomposition) and identifying patterns to solve them (pattern recognition). Think of it like solving a jigsaw puzzleβ€”each piece contributes to the bigger picture.

    Take a moment to think of a daily activity, like making a cup of tea. How would you break this activity into smaller steps? Write down the steps in your notebook before moving on.

    2 - Setting Up Thonny

    In this step, you will set up the Thonny editor, which is a beginner-friendly Python editor. Follow these steps:

    1. Go to the Thonny website by clicking here.
    2. Download the appropriate version of Thonny for your operating system (Windows, macOS, or Linux).
    3. Run the installer and follow the on-screen instructions to complete the installation.
    4. Once installed, open Thonny. You should see a simple interface with a space to write your code and a console at the bottom to see the output.

    Once Thonny is set up, you're ready to start coding!

    3 - Decomposition Exercise: Simple Calculator

    Now lets create a simple calculator in Python that can add, subtract, multiply, or divide two numbers. First, break the problem into smaller tasks:

    1. Ask the user for two numbers.
    2. Ask the user to choose an operation (add, subtract, multiply, divide).
    3. Perform the chosen operation.
    4. Display the result.

    Now, open Thonny and write the code for the calculator:

    # Simple Calculator
    def calculator():
        print("Welcome to the Simple Calculator!")
        # Step 1: Get user input
        num1 = float(input("Enter the first number: "))
        num2 = float(input("Enter the second number: "))
    
        # Step 2: Ask for the operation
        print("Choose an operation: add, subtract, multiply, divide")
        operation = input("Enter the operation: ").lower()
    
        # Step 3: Perform the operation
        if operation == "add":
            result = num1 + num2
        elif operation == "subtract":
            result = num1 - num2
        elif operation == "multiply":
            result = num1 * num2
        elif operation == "divide":
            if num2 != 0:
                result = num1 / num2
            else:
                result = "Error: Division by zero is not allowed."
        else:
            result = "Invalid operation."
    
        # Step 4: Display the result
        print("Result:", result)
    
    # Run the calculator
    calculator()
    Run your code in Thonny and test it with different inputs. Notice how breaking the problem into smaller tasks made it easier to solve.

    4 - Pattern Recognition: Identifying Even and Odd Numbers

    Pattern recognition helps us identify similarities or trends in data. For example, even numbers are divisible by 2, while odd numbers are not. In this task, you will write a Python program to identify whether a number is even or odd. Open Thonny and type the following code:

    # Even or Odd Checker
    def check_even_odd():
        print("Even or Odd Checker")
        # Get user input
        number = int(input("Enter a number: "))
    
        # Check if the number is even or odd
        if number % 2 == 0:
            print(f"{number} is an even number.")
        else:
            print(f"{number} is an odd number.")
    
    # Run the checker
    check_even_odd()

    Explanation of the code:

    • The line if number % 2 == 0: checks whether the number is divisible by 2 without leaving a remainder. The % symbol is called the modulus operator, and it gives the remainder of a division. If the remainder is 0, the number is even; otherwise, it is odd.
    Run your code in Thonny and test it with different numbers. Observe the pattern in the results and how the program identifies even and odd numbers.

    5 - Real-World Application: Password Strength Checker

    Computational thinking is used in real-world applications like password strength checkers. In this task, you will write a Python program to check the strength of a password based on these rules:

    • At least 8 characters long
    • Contains both uppercase and lowercase letters
    • Includes at least one number

    Open Thonny and type the following code:

    # Password Strength Checker
    def password_strength_checker():
        print("Password Strength Checker")
        password = input("Enter a password: ")
    
        # Check password length
        if len(password) < 8:
            print("Weak password: Must be at least 8 characters long.")
            return
    
        # Check for uppercase and lowercase letters
        if not any(char.isupper() for char in password) or not any(char.islower() for char in password):
            print("Weak password: Must include both uppercase and lowercase letters.")
            return
    
        # Check for numbers
        if not any(char.isdigit() for char in password):
            print("Weak password: Must include at least one number.")
            return
    
        print("Strong password!")
    
    # Run the password strength checker
    password_strength_checker()

    Run your code in Thonny and test it with different passwords. Notice how the program checks for multiple conditions to determine password strength.

    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 Coding Ireland. 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