Courseiva
Modules and Packages →hardMultiple Select

PCAP Modules and Packages Practice Question

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'?

⚠ Common exam trap

Python Institute often tests the distinction between importing a module versus importing an attribute from a module, and the trap here is that candidates mistakenly think 'import module.function' is valid syntax, when in fact only 'from module import function' or 'import module' (then using module.function) are correct.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

from app.operations.math_ops import calculate

It uses the standard Python import syntax to directly import the 'calculate' function from the 'math_ops' module, which is located in the 'operations' subpackage of the 'app' package. This is the most straightforward and recommended way to import a specific attribute from a module.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    from app.operations.math_ops import calculate

    Why this is correct

    The from-import statement directly fetches the 'calculate' attribute from the 'app.operations.math_ops' module and binds it in the current namespace. This is the most common and concise way to bring a function into scope, and it bypasses the need to reference the module path each time. The import system locates the module using the dotted path, then performs attribute lookup for the function.

  • ✓

    import importlib; module = importlib.import_module('app.operations.math_ops'); module.calculate()

    Why this is correct

    The importlib.import_module call enables dynamic import using a string, returning the module object rather than binding it under a fixed name. After calling it, 'module' refers to the same module object that a static import would produce, and you must use attribute access to call 'calculate' because import_module does not unpack the module's contents. This approach is useful for plugins or configurable imports where the module path is not known until runtime.

  • ✗

    import app.operations.math_ops.calculate

    Why it's wrong here

    The statement 'import app.operations.math_ops.calculate' is invalid because Python's import statement treats each dotted segment as a module or package name. Functions are attributes of modules, not sub-modules, so this syntax tries to find a module named 'calculate' inside 'math_ops' and raises a ModuleNotFoundError. To import a function, you must use the from-import form or manually reference the attribute after importing the module.

  • ✗

    from app.import operations.math_ops import calculate

    Why it's wrong here

    This line is a syntax error because the word 'import' appears after 'from' and again before the function name; the grammar is 'from <module> import <object>', and it allows only one 'import'. Additionally, the dotted path 'app.import operations.math_ops' contains a space and an invalid component 'import', which Python's parser rejects immediately. Even without the space, you cannot place 'import' inside the module path.

  • ✓

    import app.operations.math_ops; app.operations.math_ops.calculate()

    Why this is correct

    This two-statement approach imports the top-level module chain and then uses the full dotted path to access the function. Python's import machinery executes the import of 'app.operations.math_ops' and binds the name 'app' in the local (or global) namespace, making subsequent attribute access possible. While slightly verbose, it is a perfectly valid alternative that keeps the module in scope for repeated, namespaced calls.

Visual reference

Client Server SYN (seq=100) SYN-ACK (seq=200, ack=101) ACK (ack=201) Connection established — data transfer begins

About these practice questions

Courseiva writes every PCAP question from scratch — 421 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.