Module 26: Importing Modules

Unlock pre-built powers: Learn to import and use Python modules.

Anatomy of Importing

Modules give us ready-made tools. Click each part below to understand how we bring in (`import`) and use a function (`sqrt`) from the `math` module.

import math
math.sqrt(16) # Calculate square root

Identify all 8 parts!

Math Toolkit

The `math` module is full of useful functions. Import `math`, then use `math.sqrt()` to find the square root and `math.ceil()` to round *up* the number entered below. Print both results on separate lines.

Output will appear here...

Random Choices

The `random` module helps introduce unpredictability. Import `random`, then use `random.randint(1, 10)` to get a random integer and `random.choice(['red', 'green', 'blue'])` to pick a random color. Print both on separate lines.

Output will appear here...

Fix the Import Errors

Sometimes imports go wrong! Find and fix the errors in the code below so it correctly imports `math` and prints the square root of 81. Check the output carefully.

Mission: Correct Import & Usage

Goal: Import `math` and print `math.sqrt(81)` (which should be 9.0).

Module 26 Practice Complete!

Great job importing and using modules! You're leveraging Python's powerful ecosystem. Abstraction and Reusability in action!
Ready for more? Try the Advanced Practice for Module 26.