PCAP · topic practice

Modules and Packages practice questions

Practise Certified Associate Python Programmer PCAP Modules and Packages practice questions — original exam-style scenarios with answer choices, explanations, and analysis of common mistakes.

Courseiva uses original exam-style practice questions designed for learning and revision. The goal is to understand the concepts, recognise exam patterns, and improve through explanations — not memorise copied exam dumps.

Reviewed byJohnson Ajibi· MSc IT Security
20 questionsDomain: Modules and Packages

What the exam tests

What to know about Modules and Packages

Modules and Packages questions test whether you can apply the concept in context, not just recognise a definition.

How the topic appears in realistic exam-style scenarios.

Which detail in the question changes the correct answer.

How to eliminate plausible but wrong options.

How to connect the question back to the wider exam objective.

Watch out for

Common Modules and Packages exam traps

  • Answering from memory before reading the full scenario.
  • Missing a constraint such as cost, availability, security, scope or command context.
  • Choosing a broad answer when the question asks for the most specific fix.
  • Ignoring why the wrong options are tempting.

Practice set

Modules and Packages questions

20 questions · select your answer, then reveal the explanation

A developer is working on a project that requires the use of a third-party package hosted on a private repository. The developer wants to ensure that the package can be imported without specifying the full repository URL each time. Which approach should be taken?

A Python script imports the module 'my_module'. The developer wants to ensure that when the script is run directly, it executes a specific function, but when imported as a module, that function is not executed. Which code snippet achieves this?

A developer creates a package named 'analytics' with the following structure:

analytics/ __init__.py stats.py models/ __init__.py regression.py

The developer wants the statement 'from analytics import *' to import only the functions 'mean' and 'std' from stats.py. What should be added to analytics/__init__.py?

A developer is troubleshooting an ImportError: 'No module named 'config''. The config module is located in a subdirectory 'utils' relative to the script. The script's current working directory is the parent of 'utils'. Which of the following lines, added to the script, will resolve the issue?

A developer wants to import a specific function 'calculate' from a module named 'formulas' without importing the entire module. Which import statement should be used?

A developer notices that a custom package 'mypackage' is not being found when importing, even though it is installed in the site-packages directory. The developer suspects a conflict with another package of the same name. Which command should the developer run to diagnose the location from which Python is importing the package?

A developer is creating a package that contains a subpackage. The subpackage has an __init__.py file that imports a module named 'helper' from the parent package. Which import statement in the subpackage's __init__.py will correctly import 'helper'?

Which TWO of the following are valid ways to import a module named 'math' and give it an alias 'm'?

Which THREE of the following statements about Python packages and modules are true?

You are a developer at a company that builds a data processing pipeline. The pipeline consists of several Python modules organized in a package called 'pipeline'. The package structure is:

pipeline/ __init__.py load.py transform.py analyze.py

The pipeline is deployed on a server where Python 3.8 is installed. The server also has a globally installed package called 'pipeline' (from a different project) in the site-packages directory. When you run your scripts that import 'pipeline', you get unexpected behavior because Python is importing the wrong package. You need to ensure that your local 'pipeline' package is used instead of the global one. You cannot uninstall the global package because it is used by another application. You have the following options:

A) Modify the PYTHONPATH environment variable to include the directory containing your 'pipeline' package before the site-packages directory. B) Rename your local 'pipeline' package to something else and update all imports. C) Use a virtual environment specific to your project and install your package there. D) Add an __init__.py file with a special import hook to override the global package.

Which course of action is the most appropriate and reliable?

Question 11mediummultiple choice
Study the full Python automation breakdown →

A developer is troubleshooting a Python application that fails to import a custom module named 'utils'. The file 'utils.py' exists in the same directory as the main script. Which of the following is the most likely cause of the import failure?

A Python package 'mypackage' contains the following hierarchy:

mypackage/ __init__.py subpackage1/ __init__.py module_a.py subpackage2/ __init__.py module_b.py

From a script outside the package, a programmer writes:

import mypackage.subpackage1.module_a

Which statement is true about the import?

A programmer wants to create a package named 'analytics' with subpackages 'statistics' and 'ml'. Which directory structure correctly defines these packages?

A developer has a module 'config.py' with the following content:

# config.py
import os

DATABASE_URL = os.getenv('DATABASE_URL', 'localhost')

Another module 'app.py' imports config and uses DATABASE_URL. During testing, the environment variable is set correctly, but the import still uses the default value 'localhost'. What is the most likely reason?

A Python package 'shapes' has the following __init__.py:

# shapes/__init__.py
from .circle import Circle
from .square import Square

A user writes:

import shapes

c = shapes.Circle(5)

This works correctly. However, when the user writes:

import shapes.circle

c = shapes.circle.Circle(5)

It fails with AttributeError: module 'shapes' has no attribute 'circle'. What is the most likely reason?

Which TWO of the following statements about Python packages are true?

Which THREE of the following are valid ways to import a function named 'calculate' from a module named 'math_ops' located in a subpackage 'operations' of a package 'app'?

Question 18mediummultiple choice
Study the full Python automation breakdown →

You are working on a Python-based data processing pipeline that runs on a Linux server. The pipeline consists of several custom packages and modules located in /opt/mypipeline. The directory structure includes:

/opt/mypipeline/ __init__.py core/ __init__.py processor.py utils/ __init__.py logger.py

The main entry point is /opt/mypipeline/run.py, which imports modules from core and utils. The pipeline is executed using the command:

python /opt/mypipeline/run.py

Recently, the system administrator added a new Python package 'external_lib' to /opt/external_lib, and updated the PYTHONPATH environment variable to include /opt/external_lib. However, after this change, the pipeline fails to start with the following error:

ImportError: cannot import name 'process' from 'core.processor' (unknown location)

You check the PYTHONPATH and find it contains:

/opt/mypipeline:/opt/external_lib

The 'core.processor' module defines a function 'process' that is imported in run.py as:

from core.processor import process

The 'core' package has an __init__.py file. The 'external_lib' package also has a subpackage named 'core' with an __init__.py. What is the most likely cause of the import error?

A developer is writing a package that contains multiple modules. The package should allow users to import it directly and have all commonly used functions available at the package level. For example, after `import mypackage`, the user should be able to call `mypackage.func1()` without needing to import submodules. Which is the best way to achieve this?

Which TWO of the following statements about Python's `sys.path` are true?

Free account

Track your progress over time

Create a free account to save your results and see which topics improve across sessions.

Focused Modules and Packages sessions

Start a Modules and Packages only practice session

Every question in these sessions is drawn from the Modules and Packages domain — nothing else.

Related practice questions

Related PCAP topic practice pages

Move into related areas when this topic feels solid.

Frequently asked questions

What does the PCAP exam test about Modules and Packages?
Modules and Packages questions test whether you can apply the concept in context, not just recognise a definition.
How should I use these practice questions?
Select your answer before revealing the explanation. Then read why each option is right or wrong — this active recall approach builds retention far faster than re-reading notes.
Can I practise just Modules and Packages questions in a focused session?
Yes — the session launcher on this page draws every question from the Modules and Packages domain. Use a 10-question session first to gauge your baseline, then move to 20 or 30 once the weak spots are clear.
Where can I practise other PCAP topics?
Use the topic links above to move to related areas, or go back to the PCAP question bank to see all topics.
Are these real exam questions or dumps?
These are original practice questions written to test the same concepts the PCAP exam covers. They are not copied from any real exam or dump site.