Skip to content

Using Libraries and ModulesActivities & Teaching Strategies

Active learning works for this topic because students need to experience firsthand how libraries and modules solve problems efficiently. When they compare manual code to library-based solutions, they see the value of reuse immediately, which builds confidence in using pre-written code.

JC 2Computing4 activities20 min35 min

Learning Objectives

  1. 1Identify the purpose and common types of libraries and modules in programming.
  2. 2Explain how importing and using functions from libraries reduces code redundancy and development time.
  3. 3Demonstrate the ability to import a specified library and call at least one of its functions with appropriate arguments.
  4. 4Analyze the structure of a simple library's documentation to locate and use a desired function.
  5. 5Compare the code required to perform a task with and without using a relevant library.

Want a complete lesson plan with these objectives? Generate a Mission

25 min·Pairs

Pair Coding: Random Dice Roller

Students pair up to import the random module, write a program simulating 50 dice rolls, and output frequency counts. They then modify it to compare results with manual randomness. Pairs present one insight to the class.

Prepare & details

What is a library or module in programming?

Facilitation Tip: During Pair Coding: Random Dice Roller, circulate and ask pairs to explain why using the random module is better than writing their own random number logic from scratch.

30 min·Small Groups

Small Group: Math Module Challenges

Groups import the math module, solve tasks like calculating circle areas or converting degrees to radians. Each group documents one function's syntax and tests edge cases. Share via class repository.

Prepare & details

How can using existing code save time and effort?

Facilitation Tip: For Math Module Challenges, provide a starter snippet with a missing import to see which groups recognize the error independently.

20 min·Individual

Individual: DateTime Formatter

Students import datetime, create a script displaying current date in three formats, and add user input for future dates. Test and note any import errors encountered.

Prepare & details

Find and use a simple library function to perform a common task (e.g., generate a random number).

Facilitation Tip: In the DateTime Formatter activity, ask students to document the parameters for datetime.strftime() in their own words before writing code.

35 min·Whole Class

Whole Class: Library Hunt Relay

Divide class into teams; teacher posts tasks like 'sort a list.' Teams race to find, import, and demo modules like sorted() or statistics. Discuss winners' choices.

Prepare & details

What is a library or module in programming?

Teaching This Topic

Teach this topic by starting with concrete examples students can run immediately, then gradually abstracting to concepts like namespaces and documentation. Avoid overwhelming students with theory early; let them experience the benefits before formalizing. Research shows that students grasp import statements better when they see immediate, visible results from their code.

What to Expect

Successful learning looks like students confidently importing and using modules, explaining why libraries save time, and debugging minor import errors. They should articulate the difference between writing logic themselves and leveraging existing functions.

These activities are a starting point. A full mission is the experience.

  • Complete facilitation script with teacher dialogue
  • Printable student materials, ready for class
  • Differentiation strategies for every learner
Generate a Mission

Watch Out for These Misconceptions

Common MisconceptionDuring Pair Coding: Random Dice Roller, watch for students who believe random number generation requires complex logic.

What to Teach Instead

Have pairs compare their manual random logic with the one-liner using the random module, highlighting how the library handles edge cases like seeding and distributions.

Common MisconceptionDuring Math Module Challenges, watch for students who think using math.sqrt(16) is 'cheating' because it's pre-written.

What to Teach Instead

Ask groups to time themselves writing a square root function manually versus using math.sqrt, then reflect on why libraries are designed for precision and speed.

Common MisconceptionDuring Library Hunt Relay, watch for students who assume all libraries work the same way without checking documentation.

What to Teach Instead

Require teams to read the official docs for each library they find and explain one parameter or function in their own words before moving on.

Assessment Ideas

Quick Check

After Pair Coding: Random Dice Roller, display a code snippet like 'import random; print(random.randint(1, 6))' and ask students to identify the library, function, and output on a sticky note before leaving class.

Exit Ticket

After Math Module Challenges, give students the task 'calculate the hypotenuse of a triangle with sides 3 and 4' and ask them to write the code using math.sqrt, explaining why it’s more reliable than manual calculation.

Discussion Prompt

During Library Hunt Relay, have each team share one library they discovered and justify why it would be useful for a real-world project, such as a weather app or game.

Extensions & Scaffolding

  • Challenge students to modify the Dice Roller to simulate a 20-sided die game and calculate probabilities for rolling doubles.
  • Scaffolding: For students struggling with imports, provide a partially filled code template with the correct import statement and function call but missing arguments.
  • Deeper exploration: Ask students to research and present on how Python locates imported modules, including the role of sys.path.

Key Vocabulary

LibraryA collection of pre-written code, functions, and data structures that can be reused by programmers to add specific functionalities to their own programs without having to write them from scratch.
ModuleA file containing Python definitions and statements. It is a way to organize code into logical units, and can be imported into other Python programs or modules.
Import statementA command used in programming to make the code (functions, classes, variables) from one module or library available for use in the current program.
Function callThe act of executing a specific piece of code (a function) that has been defined either within the program or in an imported library. This often involves passing specific values (arguments) to the function.

Suggested Methodologies

Ready to teach Using Libraries and Modules?

Generate a full mission with everything you need

Generate a Mission