AlgoMaster Logo

Modules & Packages - Quiz

Last Updated: January 3, 2026

Modules & Packages Exercises

30 quizzes

1
Code Completion

Complete the import so you can calculate the square root of 49 using the math module

python
1
print(.sqrt(49))

Click an option to fill the blank:

2
Code Completion

Complete the code so it imports the greet function directly from the helpers module inside tools package

python
1
from tools.helpers import

Click an option to fill the blank:

3
Code Completion

Complete the expression so it shows the absolute filesystem path of the current file using the os.path module

python
1
print(os.path.(__file__))

Click an option to fill the blank:

4
Multiple Choice

What is a Python module?

5
Multiple Choice

Which import statement avoids bringing all names from a module into the current namespace?

6
Multiple Choice

Which statement correctly imports the random module with an alias?

7
Multiple Choice

You have a directory analytics with several .py files and an empty __init__.py. What is analytics considered?

8
Multiple Choice

Which __init__.py feature controls what is imported with from package import *?

9
Multiple Choice

Which module from the standard library is best suited for working with JSON data?

10
Multiple Choice

Which pip command upgrades an already installed package named requests?

11
Multiple Choice

Why are virtual environments commonly used in Python projects?

12
Multiple Choice

You want to use only the date class from datetime. Which import is most appropriate?

13
Multiple Choice

Where does Python look first when you import a module named mytool?

14
Multiple Choice

Which statement about creating a module is accurate?

15
Multiple Choice

Which standard library module helps build file paths in a platform-independent way?

16
Sequencing

Order the steps to create and use a simple custom module named math_tools in the same directory.

Drag and drop to reorder, or use the arrows.

17
Sequencing

Order the steps to create a reusable package named utilities with a string_tools module and use it.

Drag and drop to reorder, or use the arrows.

18
Output Prediction

What is the output of this code using a custom module?

1import math
2angle = 3.1415926535
3result = round(math.cos(angle), 1)
4print(result)
19
Output Prediction

What does this from...import code print?

1from math import sqrt
2value = sqrt(81)
3print(int(value))
20
Output Prediction

What is the single line of output?

1import json
2data = {"user": "Ana", "active": True}
3text = json.dumps(data)
4print("user" in text)
21
Output Prediction

What is the output related to search paths?

1import sys
2print(isinstance(sys.path, list))
22
Output Prediction

What is printed when importing from a package's __init__.py?

1package_name = "tools"
2print(package_name.upper())
23
Bug Spotting

Find the bug in this code that tries to use a function from a module in the same package.

Click on the line(s) that contain the bug.

python
1
from .math_tools import add_numbers
2
 
3
def total_price(prices):
4
    result = 0
5
    for price in prices:
6
        result = add_number(result, price)
7
    return result
24
Bug Spotting

Find the bug in this code that serializes data to JSON.

Click on the line(s) that contain the bug.

python
1
import json
2
 
3
def save_user(user_dict, file_obj):
4
    text = json.load(user_dict)
5
    file_obj.write(text)
6
    return text
25
Matching

Match each tool with what it primarily manages.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

26
Matching

Match the import style with what it provides.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

27
Fill in the Blanks

Complete the code to create a package shortcut in __init__.py that exposes selected utilities.

python
1
# utilities/__init__.py
2
from .string_tools import
3
from .math_tools import
4
5
__all__ = [, ]

Click an option to fill blank 1:

28
Fill in the Blanks

Complete the code to create and use a virtual environment-friendly requirements file.

python
1
import subprocess
2
3
def export_requirements(env_python, output_file):
4
command = [env_python, , , ]
5
with open(output_file, "w", encoding="utf-8") as handle:
6
subprocess.run(command, stdout=handle, check=True)

Click an option to fill blank 1:

29
Hotspot Selection

Click the line that directly controls which names are imported with from tools import *.

Click on the line to select.

python
1
import math
2
 
3
__all__ = ["analyze", "summarize"]
4
 
5
def analyze(data):
6
    return len(data)
7
 
8
def summarize(data):
9
    return sum(data) / len(data)
30
Hotspot Selection

Click the line that activates a virtual environment's Python interpreter in this helper function.

Click on the line to select.

python
1
import subprocess
2
 
3
def run_in_env(env_python, script_path):
4
    command = [env_python, script_path]
5
    return subprocess.run(command, check=True)