Chapter 1 · Section 2 practice

Modules and Imports

Work from question 1 to 10. Edit your Python box, click Run Code, review the result, then click Submit attempt. Reference answers unlock after all ten attempts are submitted. This records completion, not correctness. Each box runs independently. Progress is saved in this browser.

Submitted: 0 / 10

1. Use a standard module

Warm-up. Import math and print sqrt(25) through the module prefix.

Write your answer, then run it.

2. Use an alias

Warm-up. Import math as m and print sqrt(36).

Write your answer, then run it.

3. Import one function

Warm-up. Import sqrt from math and print sqrt(49).

Write your answer, then run it.

4. Rename one function

Build your skills. Import sqrt as root and print sqrt(81).

Write your answer, then run it.

5. Fix the call

Build your skills. With alias m, write a matching call for sqrt(100). Explain the planned mismatch in a comment.

Write your answer, then run it.

6. Explain an installation command

Build your skills. Store !pip install isom2600 --quiet as a string and print it. Explain !, isom2600, and --quiet in comments. Do not install anything here.

Write your answer, then run it.

7. Recognize a submodule

Build your skills. Import matplotlib.pyplot as plt and SciPy stats as stats. Print their actual names using __name__.

Write your answer, then run it.

8. Compare three forms

Challenge. Calculate sqrt(121) using math.sqrt, alias m, and directly imported sqrt. Print each result on its own line.

Write your answer, then run it.

9. Inspect available names

Challenge. Use dir(m) to print whether math contains sqrt and median. Explain in a comment why a module does not supply every possible function.

Write your answer, then run it.

10. Choose setup steps

Challenge. A new Colab runtime lacks isom2600. Print its installation command and import statement as text, in order. Explain the order and why neither is needed in these website boxes.

Write your answer, then run it.

Reference answers are locked until all 10 attempts are submitted.