Hands-on Activity Python Functions Using Copilot

Quick Look

Grade Level: 9 (9-12)

Time Required: 45 minutes

Expendable Cost/Group: US $0.00

Group Size: 1

Activity Dependency: None

Subject Areas: Computer Science

NGSS Performance Expectations:

NGSS Three Dimensional Triangle
HS-ETS1-2
HS-ETS1-4

A photo of two students working through the Copilot worksheet.
Students are learning about functions by working through the Copilot worksheet.
copyright
Copyright © Brian Herrod

Summary

Students use Microsoft Visual Studio Code and GitHub Copilot to master writing functions in Python, actively assessing the effectiveness of these tools to define future success criteria for engineers developing similar technologies. Through hands-on coding activities, they explore the significance of functions, enhancing code readability and enabling more innovative programming approaches. Additionally, students examine the impact of these technologies in programming, offering valuable suggestions to refine and advance engineering tools.
This engineering curriculum aligns to Next Generation Science Standards (NGSS).

Engineering Connection

The concepts in this activity relate to real-world engineering by focusing on problem-solving and optimization. Functions in programming help create organized, reusable code, similar to designing efficient systems in engineering. Using Visual Studio Code and Copilot introduces students to tools that streamline workflows, enhancing productivity, much like the technologies engineers use. By evaluating and improving these tools, students engage in critical thinking and iterative testing, reflecting real-world engineering practices. This hands-on experience helps them develop and refine solutions effectively.

Learning Objectives

After this activity, students should be able to:

  • Identify functions in Python and describe the role of functions in designing software.
  • Identify a standard workflow for interacting with Copilot.
  • Write effective functions with the assistance of Copilot.

Educational Standards

Each TeachEngineering lesson or activity is correlated to one or more K-12 science, technology, engineering or math (STEM) educational standards.

All 100,000+ K-12 STEM standards covered in TeachEngineering are collected, maintained and packaged by the Achievement Standards Network (ASN), a project of D2L (www.achievementstandards.org).

In the ASN, standards are hierarchically structured: first by source; e.g., by state; within source by type; e.g., science or mathematics; within type by subtype, then by grade, etc.

NGSS Performance Expectation

HS-ETS1-2. Design a solution to a complex real-world problem by breaking it down into smaller, more manageable problems that can be solved through engineering. (Grades 9 - 12)

Do you agree with this alignment?

Click to view other curriculum aligned to this Performance Expectation
This activity focuses on the following Three Dimensional Learning aspects of NGSS:
Science & Engineering Practices Disciplinary Core Ideas Crosscutting Concepts
Design a solution to a complex real-world problem, based on scientific knowledge, student-generated sources of evidence, prioritized criteria, and tradeoff considerations.

Alignment agreement:

Criteria may need to be broken down into simpler ones that can be approached systematically, and decisions about the priority of certain criteria over others (trade-offs) may be needed.

Alignment agreement:

NGSS Performance Expectation

HS-ETS1-4. Use a computer simulation to model the impact of proposed solutions to a complex real-world problem with numerous criteria and constraints on interactions within and between systems relevant to the problem. (Grades 9 - 12)

Do you agree with this alignment?

Click to view other curriculum aligned to this Performance Expectation
This activity focuses on the following Three Dimensional Learning aspects of NGSS:
Science & Engineering Practices Disciplinary Core Ideas Crosscutting Concepts
Use mathematical models and/or computer simulations to predict the effects of a design solution on systems and/or the interactions between systems.

Alignment agreement:

Both physical models and computers can be used in various ways to aid in the engineering design process. Computers are useful for a variety of purposes, such as running simulations to test different ways of solving a problem or to see which one is most efficient or economical; and in making a persuasive presentation to a client about how a given design will meet his or her needs.

Alignment agreement:

Models (e.g., physical, mathematical, computer models) can be used to simulate systems and interactions—including energy, matter, and information flows—within and between systems at different scales.

Alignment agreement:

Suggest an alignment not listed above

Materials List

Each student needs:

Worksheets and Attachments

Visit [www.teachengineering.org/activities/view/mis-2925-python-functions-copilot-computer-science-activity] to print or download.

Pre-Req Knowledge

Students should have a basic understanding of Python's indentation rules and the use of comments. Note: Students do not need to be familiar with other Python syntax yet. However, they should have Visual Studio Code and the latest version of Python installed on their devices.

Introduction/Motivation

Today, we are diving into an exciting activity that blends Python programming with an advanced tool from GitHub called Copilot. By the end of this lesson, you will have a solid understanding of how to write effective functions in Python and use Copilot to solve programming tasks more efficiently. But first, let’s set the stage with a real-world scenario.

A screenshot of a function created in Visual Studio Code.
Using Copilot in Visual Studio Code allows students to concentrate on problem decomposition and debugging rather than worrying about syntax.
copyright
Copyright © Brian Herrod
Imagine you are an engineer working on a new app to help people track their daily water intake. Your task is to create a function that takes the number of glasses of water someone has drunk and gives them feedback on whether they are meeting their daily goal. How would you design this function? What steps would you take?

Now, let us think about the tools we have at our disposal. In the professional world, engineers often rely on advanced tools to tackle complex tasks. One such tool is Copilot, which helps write code more efficiently. However, just like in real life, we must ensure we assign tasks to Copilot that are manageable. Asking it to handle overly large or complex problems can lead to issues—just like trying to solve a massive problem without breaking it into smaller, manageable parts.

Here is a question for you: What do you think makes a task reasonable for Copilot to solve? Why is it important to break down large problems into smaller, manageable parts? (Possible answers could include managing complexity, making debugging easier, and ensuring each part of the code works correctly.)

Breaking tasks into smaller, manageable functions is a critical strategy in both programming and engineering. This approach makes code more readable, easier to test, and more efficient. It is similar to how engineers design systems in the real world. For instance, when designing a car, engineers do not build it all at once. Instead, they focus on smaller components such as the engine, transmission, and electrical system, ensuring that each part works correctly before assembling the whole.

Think about a time when you had a big project or problem to solve. How did you break it into smaller tasks? How did that help you? (Allow students to share experiences, such as organizing an event or working on a group project.)

Today, we will practice writing functions in Python and using Copilot to assist us. Remember, our goal is to learn how to create effective, manageable functions and to understand how Copilot can support this process. Let’s get started!

Procedure

Background

Advanced AI tools, such as Copilot, can enhance coding by allowing programmers to write code using natural language prompts. These tools generate code snippets that perform specific tasks, speeding up the coding process and aiding learning. However, students must understand what constitutes a reasonable task for these tools. Tasks should be clear, specific, and not overly complex.

Problem decomposition is crucial in engineering. Engineers break down complex problems into smaller parts, similar to how functions work in programming. For example, designing a car involves creating and integrating subsystems such as the engine and braking system. Each subsystem must function correctly before integration, paralleling how functions should work well on their own before becoming part of a larger program.

When introducing functions, emphasis should be placed on problem decomposition, which breaks down large problems into smaller tasks. Students should be guided to write clear and specific prompts while using Copilot.

Using the worksheet, you can help students understand functions in Python and effectively use advanced tools, enhancing their programming skills and problem-solving abilities. This approach prepares students for software engineering and equips them with critical thinking skills for various engineering disciplines.

Before the Activity

During the Activity

Introduction

  1. Have students use paper and pen to answer the following questions:
    • What do you think a function in programming allows us to do?
    • Why do you think functions are important?
    • Think of a way you use functions in your daily life. Describe what that looks like.
    • What makes an AI tool for coding “good”? Why?
    • As computer scientists engineer new tools to assist in programming, what do you think the role of these tools should be? Should we rely only on AI tools, or should we write our own code as well?
  1. Facilitate a class discussion based on the students' answers to the questions above. Guide the discussion to explore their thoughts and deepen their understanding. (See the Pre-Activity Assessment section below for potential answers to the presented questions.)

Activity Setup

  1. Hand out one Getting Started With Visual Studio Code and Copilot document to each student.
  2. Give students time to read the document.
  3. Give students time to download Copilot, Visual Studio Code, and Python. Assist as needed.
  4. Give students time to follow through the “Introduction to Copilot and Visual Studio Code” section of the Getting Started With Visual Studio Code and Copilot document. Assist as needed.

Python Activity

  1. Give each student one Creating Functions in Python With Copilot Worksheet. (Note: This will guide them through the activity and provide assessment questions they will need to answer as they progress through it.)
  2. With students, read the Introduction section of the Creating Functions in Python With Copilot Worksheet.
  3. Give students time to work through Exercises 1-5.
  4. As students finish, have them compare code snippets with a classmate.
  5. When everyone is finished (or mostly finished), walk the entire class through each line of code, explaining what it does. Have students take notes.
  6. Optional: Have students work at their own pace to complete the remainder of the activities.
    A photo of two students working through the Copilot worksheet.
    Students are learning about functions by working through the Copilot worksheet.
    copyright
    Copyright © Brian Herrod

Reflection

  1. Have students complete the Reflection section of their Creating Functions in Python With Copilot Worksheet.
  2. Hand out one Exit Ticket to each student.
  3. Give students time to answer the Exit Ticket questions.

Vocabulary/Definitions

artificial intelligence (AI): The simulation of human intelligence in machines that are programmed to think, learn, and problem-solve like humans.

compiler: A software program that translates source code written in a high-level programming language into machine code or an intermediate code, allowing the computer to execute the program.

Copilot: A software assistant, powered by AI, which helps users by providing real-time suggestions, automating tasks, and enhancing productivity in various applications.

function: A reusable block of code designed to perform a specific task.

problem decomposition: A systematic approach used to break down a complex problem or task into smaller, more manageable parts.

Python: A high-level, interpreted programming language known for its readability, simplicity, and versatility, used for a wide range of applications from web development to data analysis and artificial intelligence.

Assessment

Pre-Activity Assessment

Introduction questions and class discussion: Ask students to write answers to the following questions and encourage a class discussion so they can share their thoughts.

  • What do you think a function in programming allows us to do?
    • Answer: A function performs a specific task, making it reusable and helping to keep the code organized.
  • Why do you think functions are important?
    • Answer: Functions improve code readability, reduce redundancy, and make it easier to debug and maintain the code.
  • Think of a way you use functions in your daily life. Describe what that looks like.
    • Answer: Making a sandwich can be seen as a function: get bread, add ingredients, and assemble.
  • What makes an AI tool for coding “good”? Why?
    • Answer: A good AI tool should provide accurate, relevant suggestions and help improve coding efficiency.
  • As computer scientists engineer new tools to assist in programming, what do you think the role of these tools should be? Should we rely only on AI tools, or should we write our own code as well?
    • Answer: AI tools should assist but not replace human coding. We should use them to enhance our productivity while still developing our own coding skills.

Activity Embedded (Formative) Assessment

Worksheet: Have students work individually on the Creating Functions in Python With Copilot Worksheet. After they finish, have them compare code snippets with a classmate.

Post-Activity (Summative) Assessment

Reflection question: Have students answer the following in the Creating Functions in Python With Copilot Worksheet:

Think about a time when you had a big project or problem to solve. How did you break it down into smaller tasks? How did that help you? Write a short paragraph explaining your experience and how it relates to what you learned today.

Exit Tickets: Collect Exit Tickets from students at the end of the activity.

Activity Scaling

For upper levels: Have students compare the efficiency and accuracy of writing Python functions with and without Copilot. Instructions:

  • Divide the class into two groups. Group A will write a set of Python functions using Copilot, while Group B will write the same functions without any AI assistance (they can use pseudocode).
  • Provide both groups with a list of tasks, such as:
    • Writing a function to calculate the factorial of a number.
    • Writing a function to check whether a string is a palindrome.
    • Writing a function to find the greatest common divisor (GCD) of two numbers.
  • Evaluate the efficiency and accuracy of the functions written by both groups.

Subscribe

Get the inside scoop on all things TeachEngineering such as new site features, curriculum updates, video releases, and more by signing up for our newsletter!
PS: We do not share personal information or emails with anyone.

More Curriculum Like This

High School Lesson
Exploring Nondestructive Evaluation Methods

Students learn about nondestructive testing, the use of the finite element method (systems of equations) and real-world impacts, and then conduct mini-activities to apply Maxwell’s equations, generate currents, create magnetic fields and solve a system of equations. They see the value of NDE and FEM...

Copyright

© 2025 by Regents of the University of Colorado; original © 2024 Michigan State University

Contributors

Brian Harrod, Arun Ross, Redwan Sony, Debasmita Pal, Parisa Farmanifard

Supporting Program

Research Experience for Teachers (RET), Computer Science Department, Michigan State University

Acknowledgements

This curriculum was developed through the Michigan State University College of Engineering NSF RET program under grant number CNS-1854985 under National Science Foundation. However, these contents do not necessarily represent the policies of the NSF, and you should not assume endorsement by the federal government.

Last modified: January 17, 2025

Free K-12 standards-aligned STEM curriculum for educators everywhere.
Find more at TeachEngineering.org