# math_utils.py
def add(a, b):
return a + b
def multiply(a, b):
return a * b
# main.py
from math_utils import add
result = add(5, 3) * 2
print(result)Predict the output: What will be printed when Hari executes the following code that imports and uses a module function?
16
8
NameError: name 'multiply' is not defined
ImportError: cannot import name 'add'
Show answer & explanationAnswer
Correct answer
16
Explanation
The `add` function is imported and called with arguments 5 and 3, returning 8, which is then multiplied by 2 to get 16.
Written by ExamHoot EditorialPublished · Updated
All 40 Modules and Imports questions
- 1.What is the primary purpose of using modules in Python programming?
- 2.What does the import statement accomplish when you write 'import math'?
- 3.What is the difference between 'import module' and 'from module import name'?
- 4.What does the 'as' keyword do when used in an import statement?
- 5.What happens when you execute 'from module import *' in your Python script?
- 6.What is a package in Python and how does it relate to modules?
- 7.What is the purpose of the __init__.py file in a Python package?
- 8.What does the __name__ variable represent when a module is run directly?
- 9.What is the purpose of using 'if __name__ == "__main__":' in a Python module?
- 10.What is the Python Standard Library and what role do modules play in it?
- 11.What is the sys.path variable and how does it relate to module imports?
- 12.What happens when you import a module that has already been imported in your Python session?
- 13.What is the difference between absolute and relative imports in Python?
- 14.What does the dir() function do when called on an imported module?
- 15.What is the help() function used for when working with modules and their contents?
- 16.What is the primary purpose of using modules in Python programming?
- 17.What will be the output when Hari executes the following code snippet?
- 18.Predict the error that occurs when Prasath runs this code snippet?
- 19.What is the difference between using `import math` versus `from math import sqrt` in Python?
- 20.What will happen when Vikram attempts to import a module using a relative import in the main script?
- 21.Predict the output of the following code when Anjali executes it?
- 22.What is the correct way to import all public functions from a module while avoiding namespace pollution?
- 23.What error will Ravi encounter when running this code snippet?
- 24.What does the __name__ variable represent in a Python module and how is it used?
- 25.What will be the result when Deepak executes the following code snippet?
- 26.What is the purpose of the __all__ variable in a Python module and how does it affect wildcard imports?
- 27.Predict what error Arjun will encounter when executing this code snippet?
- 28.What will be the output when Sneha runs this code that demonstrates module reloading?
- 29.How do circular imports occur in Python modules and what strategy should Rajesh use to resolve them?
- 30.What will happen when Meera executes this code involving module attributes and dynamic imports?
- 31.Predict the behavior when Nikhil attempts to use this code with conditional module imports?
- 32.What is the correct interpretation of module search paths and how does Python locate modules during import?
- 33.What error will Karan get when running this code that attempts to import with incorrect syntax?
- 34.What will be the result when Priya executes this code demonstrating module introspection?
- 35.How should Sanjay properly structure a package with multiple modules and what role does __init__.py play in package imports?
- 36.What is the primary purpose of using modules in Python, and how do they help in organizing large projects?
- 37.Predict the output:
- 38.What is the difference between using 'import module' and 'from module import function' in Python, and when should each be used?
- 39.Debug the code:
- 40.What is the purpose of the __name__ == '__main__' idiom in Python, and how does it relate to module imports?
